Alternative to Intent.FLAG_ACTIVITY_CLEAR_TASK

后端 未结 6 1253
傲寒
傲寒 2021-02-06 22:59

I have two apps App-B launches App-A. If the user starts App B from inside App A I call finish on App-A so I have no problem.

If the user goes straight to App B from th

6条回答
  •  逝去的感伤
    2021-02-06 23:30

    Using FLAG_ACTIVITY_CLEAR_TASK clears the back stack. If I'm understanding correctly, this is the behavior you want.

    Using singleInstance instead of singleTask in your manifest will do this.

    In the comments you said that it must be singleTask. I'm assuming this is because you need the back stack in certain circumstances.

    Since launchMode can't be changed programaticaly and FLAG_ACTIVITY_CLEAR_TASK is not availble for API <=10, you may have to create two identical activities.

    One with launchMode=singleTask and one with launchMode=singleInstance.

    Add this to the one using singleInstance to get a clear stack when launched from the app drawer:

     
    

提交回复
热议问题