Android: Clear the back stack

前端 未结 30 2392
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 06:47

In Android I have some activities, let\'s say A, B, C.

In A, I use this code to open B:

Intent intent = new Intent(this, B.class);
startActivity(inte         


        
30条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 07:27

    I found an interesting solution which might help. I did this in my onBackPressed() method.

    finishAffinity();
    finish();
    

    FinishAffinity removes the connection of the existing activity to its stack. And then finish helps you exit that activity. Which will eventually exit the application.

提交回复
热议问题