onCreate always called if navigating back with intent

后端 未结 1 1568
借酒劲吻你
借酒劲吻你 2020-12-19 05:17

I have an activity called HomeActivity that has a SurfaceView and shows a camera preview picture. This activity is quiet heavy and feels slow if you are starting/restarting

相关标签:
1条回答
  • 2020-12-19 06:01

    Yes, when you want to return to the HomeActivity, you need to use these flags:

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
    

    Here's the relevant section from the documentation on Intent.FLAG_ACTIVITY_CLEAR_TOP:

    The currently running instance of activity B in the above example will either receive the new intent you are starting here in its onNewIntent() method, or be itself finished and restarted with the new intent. If it has declared its launch mode to be "multiple" (the default) and you have not set FLAG_ACTIVITY_SINGLE_TOP in the same intent, then it will be finished and re-created; for all other launch modes or if FLAG_ACTIVITY_SINGLE_TOP is set then this Intent will be delivered to the current instance's onNewIntent().

    0 讨论(0)
提交回复
热议问题