How to return to the latest launched activity when re-launching application after pressing HOME?

后端 未结 6 1705
臣服心动
臣服心动 2020-12-01 08:15

Familiar scenario: I have a Main activity that launches a Game activity when a button is pressed. If the user presses HOME, and then launches my applicatio

6条回答
  •  被撕碎了的回忆
    2020-12-01 08:37

    I solve the problem using the following activity stack in my application:

    LaunchActivity -> MainActivtiy -> SomeSubActivtiy

    LaunchActivtiy only verifies some parameters and launches MainActivtiy. It turned out, that MainActivity must be launched with

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    

    That combination of flags on MainActivity gives desired behaviour.

提交回复
热议问题