Finish parent and current activity in Android

前端 未结 16 3103
误落风尘
误落风尘 2020-11-27 03:40

I have 3 activities. Activity A which leads to activity B, which in turn can go back to activity A or start activity C. However, if I press back in activity C the app should

16条回答
  •  鱼传尺愫
    2020-11-27 04:00

    I don't know if this will work, but you could try it:

    • From Activity A, start activity B for a result using startActivityForResult()

    • In Activity B, when the user triggers Activity C, start activity C.

    startActivity() returns immediately, so

    • set a result that will inform A to finish as well,

    • Call finish() in B.

    • When A receives that result from B, A calls finish() on itself as well.

    Failing that, you could make Activity C into its own app and then close the first app (with A & B) after it starts the second.

    P.S. Take Falmarri's comment into consideration as you move forward!
    Good luck.

提交回复
热议问题