开发者

Android activity lifecycle state across different activities × 99416

开发者 https://www.devze.com 2023-04-06 15:42 出处:网络
I have four activities A,B,C and D. I am moving from Activity A---->B--->C--->D And from activity D i am calling activity B.

I have four activities A,B,C and D. I am moving from Activity A---->B--->C--->D

And from activity D i am calling activity B.

By the time i reach to activity D from A-B-C-D

The states of Activity A,B and C is onStop() state and activity D is onResume() state. There are two scenarios ahead: 1>I press the back button and go to activity C or 2>I invoke an event and go to Activity B.

First scenario is understood wrt activity states. D-Destroy state and C will be onrestart-onstart-onresume

Second Scenario

Activity D goes to OnStop and for Activity B-->Oncreate-Onstart-OnResume... and Activity A and C will be on onStop() state...

I wanted to know as the state of the Activity B before the event was onStop(), but inspite of calling the onRestart() method it has called the onCreate-onStart-onResume.

As, the Activity B was not destroyed than where did the Activity B which was originally on onStop() state go ........And from this activity B when i move to Act开发者_Go百科ivity C ...it calls the onCreate-onStart-onResume for Activity C....for Activity C also the one which was onStop state has not been destroyed ......got confused with the life cycle and activity stack flow....Help me on the same...


You are creating new instances of the activity that's why you are seeing the flow onCreate-onStart-onResume. you need to add flag FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY, FLAG_ACTIVITY_REORDER_TO_FRONT to your activity before starting from the stack.

0

精彩评论

暂无评论...
验证码 换一张
取 消