How to close Android application?

后端 未结 22 1518
小蘑菇
小蘑菇 2020-11-22 07:17

I want to close my application, so that it no longer runs in the background.

How to do that? Is this good practice on Android platform?

If I rely on the \"ba

22条回答
  •  野性不改
    2020-11-22 07:57

    Just to answer my own question now after so much time (since CommonsWare commented on the most popular answer telling we should NOT do this):

    When I want to quit the app:

    1. I start my first activity (either splash screen, or whatever activity is currently at the bottom of the activity stack) with FLAG_ACTIVITY_CLEAR_TOP (which will quit all the other activities started after it, which means - all of them). Just make to have this activity in the activity stack (not finish it for some reason in advance).
    2. I call finish() on this activity

    This is it, works quite well for me.

提交回复
热议问题