Android, Intent.FLAG_ACTIVITY_CLEAR_TOP seems doesn't work?

后端 未结 6 583
忘掉有多难
忘掉有多难 2020-12-16 08:25

In my menu I have some items. Home is an item of it that I want to be root of my application and whenever user clicks on it, Android clear stack and then come back to main s

6条回答
  •  眼角桃花
    2020-12-16 08:51

    Read it once and you will never have the problem in the usage of flag_activity_clear_top

    Here is a simple clarification regarding the usage of Flag_Activity_Clear_Top.

    One Liner Formula for its right use :

    It always clears the intermediate Activities ( if any ) between the calling activity and the called activity.

    Here is an Activity Flow :

    Activity A -> Activity B -> Activity C ( use flag activity clear top to go to D) ->Activity D

    In the above sequence when reaching to D if we press back then we will get Activity C->Activity B-> Activity A , as there is no INTERMEDIATE ACTIVITY between Activity C and Activity D

    Myth of some developers here is -

    After reaching the activity D by using flag activity clear top from C, they were expecting that on the press of back key from D will take them to outside the application., which will never happen.

    Flag_Activity_Clear_Top always always clears the INTERMEDIATE ACTIVITIES BETWEEN THE TWO ACTIVITIES IF ANY

提交回复
热议问题