Home>

When I press the end button, I want to end not only that activity but all the previous activities. When finish ();is used, only the activity that set the end button ends and the previous activity appears. How can I quit multiple previous activities by pressing a button? Let me tell you.

  • Answer # 1

    If taskAffinity is not set in Activity, it should be the same value by default, so you can end it together with the following code.

    ActivityCompat.finishAffinity (activity);

  • Answer # 2

    It ’s a little different from what you want, but "android: launchMode =" singleInstance " "To the target screen and declare it, the moment you open that screen, you can end the activity so far.
    If you declare that and finish the screen, the previous Activity will not appear.
    I don't know how to quit other activities. .

    AndroidManifest