How to capture the new Intent in onNewIntent()?

后端 未结 5 2055
耶瑟儿~
耶瑟儿~ 2020-12-05 09:24

I want to pass a new, but different, Intent to an Activity. How do you differentiate between the new Intent and previous Intents? What kind of code goes into onNewIntent()?

5条回答
  •  死守一世寂寞
    2020-12-05 10:13

    How an intent arrives at your activity depends on the launchMode (see the launchmode docs at http://developer.android.com/guide/topics/manifest/activity-element.html#lmode).

    • For launchmode "standard" (the default) a startActivity with a new intent will result in an onCreate with that intent to a new instance of the activity.

    • For launchmodes "singleTop" and "singleTask" a startActivity with a new intent will result in either

    a) an onCreate with that intent to a new instance of the activity (if that activity was not running) [as per "standard" above] or b) an onNewIntent with that intent to the existing activity (if that activity was already runnning).

    For b), the second intent is available in the onNewIntent parameters. What you do with it depends on your application. Some applications will just ignore it, while others will do a setIntent() and start re-initialization / update processing the new intent.

提交回复
热议问题