views:

2068

answers:

4

Is there something in the Android developer guidelines that disuades developers from providing the option to "exit" (stop running) an application from within the application itself?

I love multitasking and all but it's not clear to me why:

  • the vast majority of apps don't have their own Exit functions and hence just keep running forever
  • don't give you a choice about running when you turn on the phone - they just do by default

Both of these things lead to memory usage constantly increasing and your device running with this performance burden all of the time despite the fact that you may only want certain apps to run some of the time.

Am I missing something?

+6  A: 

Is there something in the Android developer guidelines that disuadea developers from providing the option to "exit" (stop running) an application from within the application itself?

Yes. It is generally not needed, just as it is generally not needed to restart a Web server because some user with a browser decided (s)he is done with a Web app.

the vast majority of apps don't have their own Exit functions and hence just keep running forever

They don't keep running forever. Android will close things up as needed.

don't give you a choice about running when you turn on the phone - they just do by default

Those developers aren't paying attention to me.

Both of these things lead to memory usage constantly increasing

Generally, it doesn't. If you find specific apps that do this, uninstall them.

and your device running with this performance burden all of the time

Generally, it doesn't. If you find specific apps that do this, uninstall them.

Also, this question is a duplicate of this one.

CommonsWare
To lend some support to the OP's claims, I use advanced task killer and often see a screenful of apps listed in that which have long been closed and I can't think of why they'd still be running in the background. Is that list irrelevant, e.g. are the things appearing an implementation or caching detail and not costing anything? (Note: This is with apps that ship with the phone, not things I've installed.)
Hostile Fork
You assume ATK is accurately reporting what is running. Android keeps a cache of processes from apps that had been run but are now terminated. This cache can then be used when you start up other apps later on, to save the time forking the process and initializing the Dalvik runtime. The exact rules for when it uses a process out of cache, of course, are not well known. Just because ATK claims something is in RAM does not mean it is causing any harm (e.g., using CPU, preventing other processes from having RAM).
CommonsWare
The rules are supposed to be well documented here: http://developer.android.com/guide/topics/fundamentals.html#proclifeOf course documentation can always be improved. :)Also if you really want to see what is going on, you can use "adb shell dumpsys activity" -- in that output is a list of all processes with the current memory hierarchy (the adj= value) they are in. Processes with higher numbers will be killed before ones with lower numbers. The numbers map to the categories that are in the documentation, though the exact values have changed across platform versions.
hackbod
(And actually I just realized that the current documentation will need to be updated for Froyo, where we are changing things slightly. The background and empty process categories are being merged into one LRU list. This turns out to work better for recent devices that have a lot more memory to keep many more background processes running. Without the change, you could often get into a situation where you fill your memory with background processes, and don't get to keep around any empty processes for things such as launching to receive a broadcast.)
hackbod
A: 

Essentially, there's no need for a quit button as long as the developer does a good job of designing their app. Android activities are stopped when they aren't visible and resources are needed elsewhere, so the are no longer consuming resources. You can read about the lifecycle here:

Here's a related question:

Jay Askren
+6  A: 

"Both of these things lead to memory usage constantly increasing"

Which doesn't matter since Android apps are limited to a fixed amount of RAM. Freeing RAM won't give more RAM to other apps.

Romain Guy
The limit is per app or system wide? Does less memory remaining for the system result in overall slower performance? I can't imagine that performance remains constant with 5 apps running vs 10.
Howiecamp
The limit is per app. And when the system needs RAM, it kills processes. Performance would go down if the apps are using the CPU, but apps are usually paused or stopped when put in the background (unless badly written.)
Romain Guy
A: 

From Google's Android Application Fundamentals page:

Shutting down components A content provider is active only while it's responding to a request from a ContentResolver. And a broadcast receiver is active only while it's responding to a broadcast message. So there's no need to explicitly shut down these components.

Activities, on the other hand, provide the user interface. They're in a long-running conversation with the user and may remain active, even when idle, as long as the conversation continues. Similarly, services may also remain running for a long time. So Android has methods to shut down activities and services in an orderly way:

An activity can be shut down by calling its finish() method. One activity can shut down another activity (one it started with startActivityForResult()) by calling finishActivity(). A service can be stopped by calling its stopSelf() method, or by calling Context.stopService(). Components might also be shut down by the system when they are no longer being used or when Android must reclaim memory for more active components. A later section, Component Lifecycles, discusses this possibility and its ramifications in more detail.

So it seems like Content Providers and Broadcast receivers should never be explicitly shut down, as they are inert while not handling their specific events.

As for Activities, I would argue in favor of having an end to it, but in certain cases. If your app has a finite state in which the user is done using it, why keep it alive until GC gets it? The activity manager still needs to keep track of that Activity while the user has finished their task. My best example for this is the Calculator. You open it, you have it solve a problem for you, and then you close it. If the onCreate function is so expensive that it's more effective to do onCreate once and then onRestart whenever the user moseys back to your application then you're probably doing something wrong. Maybe I'm misinterpreting how Android handles Activities, and if so I'm always interested in learning more :)

Adam