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
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.
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:
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).finish()
on this activityThis is it, works quite well for me.
i wanted to return to the home screen of my android device, so i simply used :
moveTaskToBack(true);
The best and shortest way to use the table System.exit.
System.exit(0);
The VM stops further execution and program will exit.
Put a finish();
statement as below:
myIntent.putExtra("key1", editText2.getText().toString());
finish();
LoginActivity.this.startActivity(myIntent);
In every activity.
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.