How to capture the new Intent in onNewIntent()?

后端 未结 5 2038
耶瑟儿~
耶瑟儿~ 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:07

    If you don't want your activity to re-use the new intent in every subsequent onResume() I would recommend to store the intent in an instance field instead of via setIntent(intent).

    That way you can reset that instance field to null once you have consumed the intent without throwing away the original launch intent.

    More details in my answer here: https://stackoverflow.com/a/21261404/621690

    setIntent(Intent) has been described as a mistake by an Android Framework Engineer: https://groups.google.com/forum/#!topic/android-developers/vrLdM5mKeoY

提交回复
热议问题