How to close Android application?

后端 未结 22 1112
小蘑菇
小蘑菇 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:55

    Not possible with 2.3. I search alot, and tried many apps. The best solution is to install both (go taskmanager) and (fast reboot). When use them together it will work, and will free the memory. Another option is to upgrade to android ice cream sandwich 4.0.4 which allow control (close) of apps.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-22 07:57

    i wanted to return to the home screen of my android device, so i simply used :

    moveTaskToBack(true);
    
    0 讨论(0)
  • 2020-11-22 07:59

    The best and shortest way to use the table System.exit.

    System.exit(0);
    

    The VM stops further execution and program will exit.

    0 讨论(0)
  • 2020-11-22 08:02

    Put a finish(); statement as below:

    myIntent.putExtra("key1", editText2.getText().toString());
    
    finish();
    
    LoginActivity.this.startActivity(myIntent);
    

    In every activity.

    0 讨论(0)
  • 2020-11-22 08:03

    This is how Windows Mobile has worked for... well... ever! Here's what Microsoft have to say on the matter:

    http://blogs.msdn.com/windowsmobile/archive/2006/10/05/The-Emperor-Has-No-Close.aspx (is it sad that I remembered the title of the blog post all the way from 2006? I found the article on Google by searching "the emperor has no close" lol)

    In short:

    If the system needs more memory while the app is in the background, it’ll close the app. But, if the system doesn’t need more memory, the app will stay in RAM and be ready to come back quickly the next time the user needs it.

    Many comments in this question at O'Reilly suggest that Android behaves in much the same way, closing applications that haven't been used for a while only when Android needs the memory they're using.

    Since this is a standard feature, then changing the behavior to forcefully close would be changing the user experience. Many users would be used to the gentle dismissal of their Android apps so when they dismiss one with the intention of returning to it after performing some other tasks, they may be rather frustrated that the state of the application is reset, or that it takes longer to open. I would stick with the standard behavior because it is what is expected.

    0 讨论(0)
提交回复
热议问题