singleTask 跳转Activity Bundle和intent参数值为null

来源:互联网 发布:c语言培训班4个月出来 编辑:程序博客网 时间:2024/05/21 21:37

由于MainAcitity.class使用的是singleTask启动模式,所以别的Activity跳转到MainActivity.class后所带的参数(Intent & Bundle)均为null,这个是因为:

Bundle bundle = getIntent().getExtras();
Intent intent = getIntent();

这些方法不是在onCreate()中,所以不会加载的。

想要得到这些值,这些方法必须放在:onNewIntent(Intent intent) 中:

代码:

@Override    protected void onNewIntent(Intent intent) {        super.onNewIntent(intent);        setIntent(intent);        Bundle bundle = getIntent().getExtras();        if(bundle != null && bundle.getBoolean(StaticUtils.STARTACTIVITYRELOGIN, false)) {//如果是重新登录-->登录页返回则显示首页            com.baofoo.mobile.utils.LogUtils.d("ddfsfsdfsdfsdf1:" + bundle.getBoolean(StaticUtils.STARTACTIVITYRELOGIN));            setCurrentItem(0);        }    }


0 0