首页 > 系统 > Android > 正文

Android点击推送时处理onResume事件extras为null

2019-11-09 16:05:24
字体:
来源:转载
供稿:网友
	1、如果Activity在后台运行时,用户点击推送startActivity,在onResume事件里getIntent().getExtras等于null,这是因为getIntent()返回的是第一个Intent,不是推送里startActivity的Intent。	所以在推送里的Intent要设置为:	Intent i = new Intent();
	i.putExtras(bundle);	i.setFlafs(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);	然后在Activity里面重写onNewIntent(Intent intent)方法:	@Override	PRotected void onNewIntent(Intent intent) {  		super.onNewIntent(intent);  		setIntent(intent);	}	2、如果要切换fragment,则需要在onResume事件里处理	@Override	protected void onResume() {   		Intent intent = getIntent();
		Bundle bundle = intent.getExtras();	}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表