5

I guess this has to do with our habit on desktop computers where we

  1. open an application
  2. use it
  3. close the application

AFAIK there's no direct way from within the application to close it. And by pressing the Home button app just gets into the background. Still running.

I got a habit of pressing Home, then Recent apps and flicking all open apps out.

Is this a bad habit? Should I leave applications like GMail, FB, Currents, GNow, etc. running or is it better to close them and have as less apps as possible running?

4

4 Answers 4

6

From a developers point of view (my point of view):

Application's on Android work a specific way, they all have their own life cycle, the main ones we are talking about here is when the application is paused, or stopped (onPause, onStop) and when the application is destroyed (onDestroy), these two states are brought to light in different ways, onPause is when the user can no longer see the application, or screen, this is when the user presses home or clicks something on the screen that takes them to another screen, like pressing a link for example, there is still a possibility of you needing this screen, for example when you press the back button to get back to the screen, you still want it in the same state, so the application is still open and waiting for you to return.

The other state, when the application is destroyed, can happen three ways, firstly the developer might of added something in to close the application automatically, for example the Endomondo application you can press menu > exit, this will "close" the application and it will no longer be in memory. The next way is the user pressing back on it, as in there is no way to get back to the exact screen (for example you can't press forward to get to it) so the application is no longer needed so it is closed.

The third way that an application is destroyed, or closed, is when Android needs more memory, when this happens it clears the applications that haven't had interaction the longest. Android does this itself, if it needs more memory it will get it.

So in all leaving applications open isn't a bad happen, however some applications can still use a lot of CPU power and not memory when its in the background, if you think this is going to happen you should close it yourself, android should be able to pick up on this however

Have a look here at the states of a activity, or a screen:

Activity life cycle


EDIT:

  • Pressing back on a screen: Activity destroyed (onPause > onStop > onDestroy)
  • Swiping application away on recent apps: Activity destroyed (onPause > onStop > onDestroy)
  • Pressing home: Application kept in memory, only if the developer hasn't added a self close feature (onPause > onStop)
  • Navigating away from app, link etc: Application kept in memory, as above (onPause > onStop)
5
  • I'm a developer too so this info is very easily consumed by my brain... :) So where in the flow diagram is the event when I press the Recent apps and swipe an app off it (I understand this act as actually closing the app)? Between onPause and onStop or between onStop and onDestroy? If it's the latter, then please explain the state transition between the first one. But if it's the first one, then I can see the transition to onDestroy similar to garbage collection? Non-deterministic event? Sep 7, 2012 at 10:00
  • check out the edit, on think thats what you want.
    – FabianCook
    Sep 7, 2012 at 11:37
  • Kinnda... But I think you're wring at #1 and #4. Pressing back gets the app to stopped state and not destroyed. It's still in recent apps. So the same as pressing home. and with #4: navigating away (i.e link) gets the app into paused state as per flow diagram. Sep 7, 2012 at 15:54
  • BTW: While testing this with GMail app I actually found a bug in it when it resumes from stopped state. :) Sep 7, 2012 at 15:55
  • The activity theoretically should be finishing on 1 and I was right on 4, onPause > onStop is correct
    – FabianCook
    Sep 7, 2012 at 16:06
7

The answer is simple: Do not close apps when possible!

Android takes care of app managemnt by leaving them stick around (which is not necessary in memory) when possibile allowing faster startup times and resumption where you left. Swiping out a app of the recent app list is similar too closing it, but not the same.

0
3

This is not technically better. One of the main characteristics of Android is to simulate multitasking. When you switches the application to another (yeah, even the Home launcher is an application), Android pauses the current activity and tries to load the data of the next into memory. So, two things can happen here:

  • If there's enough free memory, the data is loaded and the new activity is started. In this scenario, there's no trouble to switch back to the last application, since it's already running;
  • If there's a lack of memory, Android have to "backup" the data of the current activity into internal storage. This has a cost and a delay; after doing that, Android can finally load the new activity into memory.

From a performance point of view, keeping as much data as you can on RAM memory is benefic. The fact that an app data is still on memory doesn't mean it's consumming battery resources, unless there's a service running, which is not always the case.

So, pressing Home or Back buttons has in practice the same effect on memory usage. Android is designed to manage RAM itself, and it's not a good idea to kill apps unless you really know what you're doing.

Many people start having problems when use many apps that run services in background. Some services tend to stay always in memory performing some task (like keeping you online, checking for new messages etc.). This costs more resources (memory and battery), and if your phone is slow everytime, it's a good idea to check which services are running and maybe uninstall some of them (you can see them in Configurations/Applications/Running services).

If you want to learn more things about that, you should take a look at this post: http://android-developers.blogspot.com.br/2010/04/multitasking-android-way.html

1

As far as I understand, Android is supposed to look after this itself. Many apps have services that run almost separately from the visible part as well and part of the lifecycle of Android apps is that the OS can indeed choose to close threads down as it sees fit.

But buried in the docs so well I don't remember quite where it is is the information that "Back"ing out of an app will tend to shut it down rather than if you just go "Home". Graphics-intensive apps like 'Angry Birds' should be closed like this, in fact, because the app gets the opportunity to shutdown processor-intensive threads properly.

Not the answer you're looking for? Browse other questions tagged .