设置Activity为singleTask之后,如何在getIntent().getStringExtra()获取数据

MainActivity清单文件

<activity
            android:name=".view.MainActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan|stateAlwaysHidden" />

设置为singleTask的Activity重写方法:

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
// must store the new intent unless getIntent() will return the old one  
        setIntent(intent);
    }

然后在获取焦点的时候,获取

  @Override
    protected void onResume() {
        super.onResume();
        String id = getIntent().getStringExtra("id");
        if (!TextUtils.isEmpty(id)) {
            //执行代码xxx
        }
    }

这样就可以收到数据了

 

posted @ 2016-07-05 17:05  丫丫25001  阅读(2073)  评论(0)    收藏  举报