tags:

views:

6914

answers:

17

Moving on in my attempt to learn Android I just read the following:

Question: Does the user have a choice to kill the application unless we put a menu option in to kill it? If no such option exists, how does the user terminate the application?

Answert (Romain Guy): The user doesn't, the system handles this automatically. That's what the activity lifecycle (especially onPause/onStop/onDestroy) is for. No matter what you do, do not put a "quit" or "exit" application button. It is useless with Android's application model. This is also contrary to how core applications work.

Hehe, for every step I take in the Android world I run into some sort of problem =(

Apparently, you cannot quit an application in Android (but Android can very well totally destroy your app whenever it feels like it). Whats up with that? I am starting to think that its impossible to write an app that functions as a "normal app" - that the user can quit the app when he/she decides to do so. That is not something that should be relied upon the OS to do.

The application I am trying to create is not an application for the Android Market. It is not an application for "wide use" by the general public, it is a business app that is going to be used in a very narrow business field.

I was actually really looking forward to developing for the Android-platform, since it addresses a lot of issues that exist in Windows Mobile and .NET. However, the last week has been somewhat of a turnoff for me... I hope I dont have to abandon Android, but it doesnt look very good right now =(

Is there a way for me to really quit the application?

+6  A: 
Christopher
Its not pointless if it fills a purpose, and in our application it does just that. For example, we want to check updates when exiting the application. We cant exit the app, then no update can be made.Some comments suggest that hitting the back button does not kill the app at all (see link in my question above).
Ted
Another thing is that I dont want the application to quit just by pressing the BACK button. It should only terminate when the Users wants to terminate it - never ever any other way.If you cant write apps that behave like that in Android, then I think that android cant be used for writing real apps =(
Ted
As Romain says, it's not how the core applications work. So if users are used to pressing "Back" to quit an app, then it seems likely that they'll continue to do so with your app rather than explicitly choosing Quit? You could do an update check at startup, or onDestroy(), or using an repeating alarm.. it doesn't seem like something that requires to be triggered by a user.
Christopher
You have to remember that the Android isn't a PC - it's a phone. It has limited resources and needs the user needs complete control (placing emergency calls, for example). What do you mean by "real apps"?
Tom R
What does the app do? If you don't want it to quit when the user hits back, use a service. If you do want it to quit, why do you care that the activity is still in memory? Why do you want to update the software on exit? The market app takes care of the updating the software for you.
Jay Askren
Tom: I have been coding for Windows Mobile for almost 5 years now. Thats a phone to with "limited resources". There is no such behaviour there, and there is not problems that it doesnt act in that "big brother"-way either. "Real apps" = where the programmer has a lot more control over it, ie quitting, when GUI-stuff is removed etc...
Ted
Jay: because if its still in memory, I cannot update the app Im thinking. Cant delelte files that are in use, right? I want to update on exit because we cannot force our users to update on start. That has to do with how they work and what they need. Its not OK for them to be forced an update at the start of their shift for different reasons. Its a bit complicated.
Ted
Jay: No, as I stated aboive it is NOT an Market App, and its not going to be that either. Its a very specialized app, not for general use.
Ted
It's a separate question in itself, but you can download the updated APK in the background at any time and show a system notification prompting the user to update, or force its installation during app startup.Installing an update is very quick and you don't need to make any assumptions about apps running/files open because, as you know, components on Android are notified when they need to shut down so state is always saved.
Christopher
+4  A: 

I think the point is that there is no need to quit the app unless you have buggy software. Android quits the app when the user is not using it and the device needs more memory. If you have an app that needs to run a service in the background, you will likely want a way to turn the service off.

For example, Google Listen continues to play podcast when the app is not visible. But there is always the pause button to turn the podcast off when the user is done with it. If I remember correctly, Listen, even puts a shortcut in the notification bar so you can always get to the pause button quickly. Another example is an app like a twitter app for instance which constantly polls a service on the internet. These types of apps should really allow the user to choose how often to poll the server, or whether even to poll in a background thread.

If you need to have code that runs on exit, you can override onPause(), onStop(), or onDestroy() as appropriate. http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

Jay Askren
Im not following you. The point is that I cannot allow for Android to determine when my app is going to be terminated. that must be the choice of the user. As I said above, there is a lot of things going on in my app (data being PUSHed to the device, lists with tasks that always should be there etc). Our users log in and cant be doing that everytime they get a phonecall and Android decides to kill the app. there are a lot of situations where I see the Android approach just not working. Bottom line: i need to write an app that acts as a normal app - user decides when quitting -not Google.
Ted
Along with other messy things I discovered, I think that developing our app for Android is not going to happen. Its too much "big brother"-thing going on, where Android tells me what app that should be running or not. I as a programmer should have that choice, not google or android =(
Ted
Your Activities -- the active user interface -- go away when another application comes on top, or you press back or whatever. The user's not interacting with them, so it's safest to save the state in case the user doesn't come back for a long time, and so on, as you know. There's nothing stopping you from writing a `Service` though to keep ongoing work happening in the background, like receiving data pushes or whatever. Google Talk doesn't stop working when you're using a different app. Same with the Music player. Look at the other apps out there and how they work.
Christopher
Before I finally give up on Android, I will take a close look at the Service approach =)
Ted
You should be able to save the credentials so users don't need to log in every time they get a phone call or go away from your app. I would recommend looking at Android's lifecycle. When the app gets paused, stopped, or destroyed, you can save all relevant data so when the app opens again, it will be as they left it. The user doesn't even need to know that the app was ever stopped.
Jay Askren
I can imagine that a user may want to quit some really resource intensive applications. Maybe it should just reduce its use of resources when it is paused, but that might not always be possible
Casebash
+4  A: 

As an Application in an Android context is just a bunch of vaguely related Activities, quitting an Application doesn't really make much sense. You can finish() an Activity, and the view of the previous Activity in the Activity stack will be drawn.

Tom R
+81  A: 

This will eventually get to your question, but I first want to address a number of issues you raise in your various comments to the various answers already given at the time of this writing. I have no intention of changing your mind -- rather, these are here for others who come to read this post in the future.

The point is that I cannot allow for Android to determine when my app is going to be terminated. that must be the choice of the user.

Millions of people are perfectly happy with the model where the environment closes up the application as needed. Those users simply don't think about "terminating" the Android app, any more than they think about "terminating" a Web page or "terminating" a thermostat.

iPhone users are much the same way, in that pressing the iPhone button does not necessarily "feel" like the app was terminated, since many iPhone apps pick up where the user left off, even if the app really was shut down (since iPhone only allows one third-party app at a time, at present).

As I said above, there is a lot of things going on in my app (data being PUSHed to the device, lists with tasks that always should be there etc).

I don't know what "lists with tasks that always should be there" means, but the "data being PUSHed to the device" is a pleasant fiction and should not be done by an activity in any case. Use a scheduled task (via AlarmManager) to update your data for maximum reliability.

Our users log in and cant be doing that everytime they get a phonecall and Android decides to kill the app.

There are many iPhone and Android applications that deal with this. Usually, it is because they hold onto logon credentials, rather than forcing users to log in every time manually.

For example, we want to check updates when exiting the application

That is a mistake on any operating system. For all you know, the reason your application is being "exited" is because the OS is shutting down, and then your update process will fail mid-stream. Generally, that's not a good thing. Either check updates on start or check updates totally asynchronously (e.g., via a scheduled task), never on exit.

Some comments suggest that hitting the back button does not kill the app at all (see link in my question above).

Pressing the BACK button does not "kill the app". It finishes the activity that was on-screen when the user pressed the BACK button.

It should only terminate when the Users wants to terminate it - never ever any other way. If you cant write apps that behave like that in Android, then I think that android cant be used for writing real apps =(

Then neither can Web apps. Or WebOS, if I understand their model correctly (haven't had a chance to play with one yet). In all of those, users don't "terminate" anything -- they just leave. iPhone is a bit different, in that it only presently allows one thing to run at a time (with a few exceptions), and so the act of leaving implies a fairly immediate termination of the app.

Is there a way for me to really quit the application?

As everybody else told you, users (via BACK) or your code (via finish()) can close up your currently-running activity. Users generally don't need anything else, for properly-written applications, any more than they need a "quit" option for using Web apps.


No two application environments are the same, by definition. This means that you can see trends in environments as new ones arise and others get buried.

For example, there is a growing movement to try to eliminate the notion of the "file". Most Web apps don't force users to think of files. iPhone apps typically don't force users to think of files. Android apps generally don't force users to think of files. And so on.

Similarly, there is a growing movement to try to eliminate the notion of "terminating" an app. Most Web apps don't force the user to log out, but rather implicitly log the user out after a period of inactivity. Same thing with Android, and to a lesser extent, iPhone (and possibly WebOS).

This requires more emphasis on application design, focusing on business goals and not sticking with an implementation model tied to a previous application environment. Developers who lack the time or inclination to do this will get frustrated with newer environments that break their existing mental model. This is not the fault of either environment, any more than it is the fault of a mountain for storms flowing around it rather than through it.

For example, some development environments, like Hypercard and Smalltalk, had the application and the development tools co-mingled in one setup. This concept did not catch on much, outside of language extensions to apps (e.g., VBA in Excel, LISP in AutoCAD). Developers who came up with mental models that presumed the existence of development tools in the app itself, therefore, either had to change their model or limit themselves to environments where their model would hold true.

So, when you write:

Along with other messy things I discovered, I think that developing our app for Android is not going to happen.

that would appear to be for the best, for you, for right now. Similarly, I would counsel you against attempting to port your application to the Web, since some of the same problems you have reported with Android you will find in Web apps as well (e.g., no "termination"). Or, conversely, someday if you do port your app to the Web, you may find that the Web app's flow may be a better match for Android, and you can revisit an Android port at that time.

CommonsWare
Beautiful Answer
David Reis
Thanks for this answer commonsware =) And I agree totally. Actually, I made the reference and comparison between Android and a webpage yesterday when I discussed these issues with my collegue with whom I work. I indeed feel that Android tries to imitate some form of webpage, and that is not what I call "a real app" (even though that is subjective of course).If the app could be transformed to a WebApp, then I might just create a webpage and ask the users to start their web browser. But thats not the case =(
Ted
Im not going to comment in detail on all what you wrote. They are all good and valid comments, but not really knowing what our apps is and how it is working today (the server structure cannot change, the idea was to port the mobile app to Android) makes it hard, of course, for you to see whats needed. Even though we "keep login credentials", that would mean that the users logs in everytime something happens on the device and the server is isnstructed to react in certain ways on login. That cant be done just randomly, as would happen in an Android-application...
Ted
Nonetheless, thanks for the answer. It was informative and appreciated =)
Ted
Mark: Thanks for the good summary. Ted: We're very slowly discovering what functionality you require, like long-lived sessions. As mentioned, you can use a Service for that. Also, I doubt that you need to log in to your app each time you interact with the server -- surely there's a session ID token you can hold onto?
Christopher
One thought that drifted in my head:If I just rewrite the whole app as a Service, and treat that Service as the actual application - perhaps that would work better? Then I could "dumb up" the Activities (just as Android wants them) to just present data contained in the Service. In that case, I could perhaps keep login state and other stuff there. Using *startForeground(int, Notification)* I can almost stop Android from killing the Service...?
Ted
Christopher: yes, your tip on using Services has been in my mind since then, see the above comment =) I also have to say that I really appreciate your comments, and everyone elses. I learn a lot, even though I get disappointed with the way things work... ;-)
Ted
Well, actually the server just keeps track of "valid TCP-connections". When the client connects to server, the server only accepts the Login-packet. If such a packet is received, then the server checks to see if login == OK. If so, the TCP-connection used to send teh Login-packet is saved in a Hash. Whenever a incoming packet is received on one of the many TCP-connections in the server, the server know what User is logged in on that TCP-connection. So if the TCP-connection dies (android killed the app), a new login is required...
Ted
"Using startForeground(int, Notification) I can almost stop Android from killing the Service...?" Assuming your users will not mind having an icon in their status bar, this should work. Or, to put it another way, if your service still gets killed due to low RAM even after using startForeground(), you have much bigger problems.
CommonsWare
How do you mean I have bigger problems? That should be the same problem I would have in a "normal non-service app" on Android?Please note that my users are professionals, that use the device for the sole purpose of using the application Im trying to port to Android. They will not be using it for anything else =)
Ted
"How do you mean I have bigger problems?" I mean that the only way this will occur is if the device is having serious memory issues, probably requiring a reboot. A startForeground() service is 2nd-to-last to have to get killed off for memory reclamation (last being the foreground activity). Since Android apps do not have unlimited heap sizes, the only way this should occur is either because lots of apps are abusing startForeground() or if the OS itself is leaking RAM.
CommonsWare
"Please note that my users are professionals, that use the device for the sole purpose of using the application Im trying to port to Android." Actually, you have indicated otherwise ("cant be doing that everytime they get a phonecall" -- a "phonecall" is not your app). Moreover, unless you are building your own device, you can't prevent people from installing other apps if they so choose.
CommonsWare
As another aside, surely you'd be caching the user's credentials anyway if you're relying on long-lived TCP connections for session management? For a mobile application, it would seem a bit crazy to expect the user to manually re-establish their session just because the device lost the network temporarily.
Christopher
While your answer is correct for Java apps, there's a good reason to kill an application completely: If you're using NDK code of an app ported, for example, from iPhone, that isn't going to expect the process to be recycled, and therefore has a pile of code with global or static values that will be in an invalid state if the application "exits" and restarts. finish() doesn't even help here, in fact; the application won't even get an onDestroy() call until well after another instance has a chance to run, reusing the process. android.os.Process.killProcess(android.os.Process.myPid()); works. :)
SomeCallMeTim
@SomeCallMeTim: No, that is not a valid reason to use `killProcess()`. It is a valid reason to write better iOS code.
CommonsWare
@CommonsWare: Sorry, but that's a trite answer that is of no use to me. I'm porting code that I'm paid to port. Should I spent twice the time doing the port, rewriting their code, or get it done in the way that reduces costs for my employer, allowing them to put more games on Android sooner? It's an entirely academic question anyway: They don't want me to make such major changes to their engine, since I can't test the changes on iOS. AND it's simply wrong: There's nothing "bad" about using Singleton patterns for appropriate objects. Android is just broken WRT NDK apps.
SomeCallMeTim
@SomeCallMeTim: "application won't even get an onDestroy() call until well after another instance has a chance to run, reusing the process" -- color me skeptical, but even then, there should be ways to address the problem without resorting to `killProcess()` (e.g., detect the change in `Application` object in your NDK library). I suggest that you open a fresh SO question so we can get more info about the exact pattern you are using and problems you are perceiving.
CommonsWare
@SomeCallMeTim: Dianne Hackborn has officially endorsed your approach, should you need it: http://groups.google.com/group/android-developers/browse_thread/thread/b48f0fa3784f8e27 -- personally, I still think we could find an alternative.
CommonsWare
+9  A: 

Ted, given your various questions on this site, it seems that you refuse to write apps the way Android apps are supposed to be written. If you don't want to write Android apps, do not write Android apps.

Romain Guy
Its not that I dont want to write them, its just that the way they are supposed to be written doesnt work for me or the project/application Im trying to port. And that is because the Android apps behave almost like webpages as someone compared them too, and that wont always work for an app =(Last hope is if I can do something with a Service...
Ted
+5  A: 

Ted, What you are trying to accomplish can be done, perhaps just not how you are thinking of it right now. I suggest you read up on Activities, and Services. Stop using the term "app" and start referring to the components, ie. Activity, Service. I think you just need to learn more about the android platform, it is a change in mindset from a standard PC app. The fact that none of your posts have had the word "Activity"(short of a FAQ quote, ie not your words) in them tells me you need to read some more.

Aaron
Ive read most of the stuff on android.com =) and I can link to several of my questions where I talk about Activities, so thats not true (ex: http://stackoverflow.com/questions/2032335/launchmodes-singletask-how-to-switch-between-screens-is-intents-the-only-way or http://stackoverflow.com/questions/2032335/launchmodes-singletask-how-to-switch-between-screens-is-intents-the-only-way etc...)However, I might give it one last go, and try to create the who "app" as a Servce...
Ted
An app can contain Services and Activitys, and it sounds like your app may need both. The activity is only the UI part.
Aaron
+1  A: 

In any case, if you want to terminate your application you can always call System.exit(0);

Tasos Kleisas
+4  A: 

I would consider reading "Android Wireless Application Development" published by Addison-Wesley. I am just finishing it up and it is VERY thorough. It appears that you have some fundamental mis--understandings of the Android platform. I too was a little frustrated at first with the application life-cycle of Android apps, but after coming to a greater understanding, I have come to really enjoy this approach. This book will answer all of your questions and much more. It really is the best resource I have found for new Android developers. Also, I think you need to let go of a line for line port of the existing app. In order to port your application to the Android platform, some of the application design is going to change. The application-lifecycle used is necessary as mobile devices have very limited resources relative to desktop systems and allows Android devices to run several applications in an orderly and resource aware fashion. Do some more in depth study of the platform and I think you will realize that what you are wanting to do is entirely feasible. Best of luck

Edit: By the way I am no way affiliated with Addison-Wesley or any person or organization associated with this book. After re-reading my post I feel that I came off a little fanboyish. I just really, really enjoyed it and found it extremely helpful. :)

Andy
Thanks for the book tip. I will take a look at it if I can and if I decide to move on the the Android port.Just to state it again though: our users are not very up-to-date when it comes to computers. I will be very hard for them to use for example the NotificationBar in Android. Too small (they have BIG fingers hehe). Its a different world for them, so we need to keep it simple and without options for the user. We built our .NET-solution with that in mind - dont give them a choice =)
Ted
I hear that. You have to assume most users are not very tech smart.
Andy
I get so tired of the mantra of how little "resources" a mobile device has. Wake up, they are running on over 500Mhz and has loads of memory. My old Dell Axim had 128MB of RAM. The current devices out there have usually over 512RAM and running on 1GHZ! That is 10 times more than my old Pentium 90Mhz, and I didnt hear ppl saying "the very limited resources" this and that. Its time to wake up and smell the coffee - we are in the 2010 now, not the 80ies.
Ted
+2  A: 

Hmmmm...

I think that you just don't see the android app the right way. You can do something nearly what you want easily :

  • do the app activities save/restore state like it is encouraged in the dev livecycle docs.

  • if at the restore stage some login is needed (no login/session info available) then do it.

  • eventually add a button/menu/timeout in which case you will do a finish() without saving the login and other session infos, making implicitely the end of app session : so it the app is started/bring to front again it will start a new session.

That way you don't really care if the app is really removed from memory or not.

If really you want to remove it from memory (this is discouraged, and btw for what use ?) you can kill it conditionnally at the end of onDestroy() with java.lang.System.exit(0) (or perhaps restartPackage(..)?). Of course do it only in the case you want to "real end the app", because the onDestroy() is part of the normal lifecycle of activities and not an app end at all.

Slig
+14  A: 

I'd just like to add a correction here for the future readers of this thread. This particular nuance has escaped my understanding for a long time so I want to make sure none of you make the same mistakes:

System.exit() does not kill your app if you have more than one activity on the stack. What actually happens is that the process is killed and immediately restarted with one fewer activity on the stack. This is also what happens when your app is killed by the Force Close dialog, or even when you try to kill the process from DDMS. This is a fact that is entirely undocumented, to my knowledge.

The short answer is, if you want to exit your application, you've got to keep track of all activities in your stack and finish() ALL of them when the user wants to exit (and no, there is no way to iterate through the Activity stack, so you have to manage all of this yourself). Even this does not actually kill the process or any dangling references you may have. It simply finishes the activities. Also, I'm not sure whether Process.killProcess(Process.myPid()) works any better; I haven't tested it.

If, on the other hand, it is okay for you to have activities remaining in your stack, there is another method which makes things super easy for you: Activity.moveTaskToBack(true) will simply background your process and show the home screen.

The long answer involves explanation of the philosophy behind this behavior. The philosophy is born out of a number of assumptions:

  1. First of all, this only happens when your app is in the foreground. If it is in the background the process will terminate just fine. However, if it is in the foreground, the OS assumes that the user wants to keep doing whatever he/she was doing. (If you are trying to kill the process from DDMS, you should hit the home button first, and then kill it)
  2. It also assumes that each activity is independent of all the other activities. This is often true, for example in the case that your app launches the Browser Activity, which is entirely separate and was not written by you. The Browser Activity may or may not be created on the same Task, depending on its manifest attributes.
  3. It assumes that each of your activities is completely self-reliant and can be killed/restored in a moment's notice. (I rather dislike this particular assumption, since my app has many activities which rely on a large amount of cached data, too large to be efficiently serialized during onSaveInstanceState, but whaddya gonna do?) For most well-written Android apps this should be true, since you never know when your app is going to be killed off in the background.
  4. The final factor is not so much an assumption, but rather a limitation of the OS: killing the app explicitly is the same as the app crashing, and also the same as Android killing the app to reclaim memory. This culminates in our coup de grace: since Android can't tell if the app exited or crashed or was killed in the background, it assumes the user wants to return where they left off, and so the ActivityManager restarts the process.

When you think about it, this is appropriate for the platform. First, this is exactly what happens when the process is killed in the background and the user comes back to it, so it needs to be restarted where it left off. Second, this is what happens when the app crashes and presents the dreaded Force Close dialog.

Say I want my users to be able to take a picture and upload it. I launch the Camera Activity from my activity, and ask it to return an image. The Camera is pushed onto the top of my current Task (rather than being created in its own Task). If the Camera has an error and it crashes, should that result in the whole app crashing? From the standpoint of the user, only the Camera failed, and they should be returned to their previous activity. So it just restarts the process with all the same Activities in the stack, minus the Camera. Since your Activities should be designed so that they can be killed and restored at the drop of a hat, this shouldn't be a problem. Unfortunately, not all apps can be designed that way, so it is a problem for many of us, no matter what Romain Guy or anyone else tells you. So, we need to use workarounds.

So, my closing advice:

  • Don't try to kill the process. Either call finish() on all activities or call moveTaskToBack(true).
  • If your process crashes or gets killed, and if, like me, you need the data that was in memory which is now lost, you'll need to return to the root activity. To do this, you should call startActivity() with an Intent that contains the Intent.FLAG_ACTIVITY_CLEAR_TOP flag.
  • If you want to kill your app from the Eclipse DDMS perspective, it had better not be in the foreground, or it will restart itself. You should press the Home button first, and then kill the process.
Neil Traft
+3  A: 

All of my applications have quit buttons... and I quite frequently get positive comments from users because of it. I don't care if the platform was designed in a fashion that applications shouldn't need them. Saying "don't put them there" is kind of ridiculous. If the user wants to quit... I provide them the access to do exactly that. I don't think it reduces how Android operates at all and seems like a good practice. I understand the life cycle... and my observation has been that Android doesn't do a good job at handling it.... and that is a basic fact.

androidworkz
+1  A: 

I agree with Ted. I understand that exiting the application is not the "android way", but it doesn't seem like it should be precluded. Here are 3 reasons why you might want a real exit to the application (not just the activity):

  1. The user might want some control over which app gets killed in the case of low memory. If important app A is running in the background, then you might like to exit app B when you are done with it so that app A doesn't get killed by the operating system.

  2. If your application has sensitive data cached in memory, you might like to kill the app so that a virus/worm/rogue app can't get at it. I know the security model is supposed to prevent that, but just in case...

  3. If your application uses resources (like network, cpu, sensors, etc) that could adversely affect the phone, then one way of ensuring that those resources are freed up is to exit the application. I understand that well-behaved apps should free up resources when they are not needed. But again, exiting the application seems like a reasonable way of ensuring that.

Burke
What do you think represents the "application"? If I open the Facebook app, and set a new profile pic - my Camera or Gallery apps start up. As a user, I'm still performing the same task (using Facebook). If I then decide to close Facebook, my Camera and Gallery apps have to close too (since they are activities launched from Facebook)... What if I was in the middle of editing some of my other pics and had only intended to close Facebook? You would have shifted the problem to potential data loss.
seanhodges
Well, I don't think it could go as far as data loss. If you have a third-party activity running in the same task as your own activity, and your own activity is the one with the exit button, then the user has to `finish()` the third party activity before he can hit the exit button. And the third party activity should be saving any unsaved information at that time. I don't think you can use the app switcher to return to the exit button activity unless it's running in a separate task. And if it's a separate task, it's a separate process, and therefore won't be killed by the exit button.
Neil Traft
In my mind, the "application" is the underlying linux process that is running all of my activities. But I am not an android guru so maybe my understanding is flawed. I write fortran number crunching code in real life, so maybe I am just a dinosaur.
Burke
1. I think 99.99% of Android users should not worry about how the OS manages applications behind the curtains. The rest are geeks and will find advanced tools do make the system behave exactly how they want.2. You can always unload any sensitive data when the activity gets paused or stopped.3. Same as above, resources can be freed in lifecycle callback methods. When the activity resumes, resources can be allocated again.
Zsolt Török
I think its rather interesting that sooo many Android users are installing "Advanced Task Killer", an app that closes down other apps since you normally cant do it yourself. I use it all the time myself. Quitting an app is not something I feel you can do without.
Ted
+5  A: 

Stop thinking of your application as a monolithic application. It is a set of UI screens that the user can interact with your "application", and "functions" provided via Android services.

Not knowing what your mysterious app "does" is not really important. Let's assume it tunnels into some super secure corporate intranet, performing some monitoring or interaction and stays logged in until the user "quits the application". Because your IT department commands it, users must be very conscious of when they are IN or OUT of the intranet. Hence your mindset of it being important for users to "quit".

This is simple. Make a service that puts an ongoing notification in the notification bar saying "I'm in the intranet, or I am running". Have that service perform all the functionality that you need for your application. Have activities that bind to that service to allow your users to access the bits of UI they need to interact with your "application". And have an Android Menu -> Quit (or logout, or whatever) button that tells the service to quit, then closes the activity itself.

This is, for all intents and purposes exactly what you say you want. Done the Android way. Look at Google Talk or Google Maps Navigation for examples of this "exit" is possible mentality. The only difference is that pressing back button out of your activity might leave your UNIX process lying in wait just in case the user wants to revive your application. This is really no different than a modern operating system that caches recently accessed files in memory. After you quit your windows program, most likely resources that it needed are still in memory, waiting to be replaced by other resources as they are loaded now that they are no longer needed. Android is the same thing.

I really don't see your problem.

Eric
+3  A: 

Methinks Ted art a troll, but setting the silly anonymity-bred nonsense aside...

If you are unable to fathom how to make your data/connections (and thereby your "application") persistent, then you will be unable to do what you "need" to do with Android.

Those who do download those cutesy little App Killers usually find they do not help battery life or memory usage, but hinder the OS from doing it's job of managing memory efficiently...

http://android-developers.blogspot.com/2010/04/multitasking-android-way.html

just peruse it... :)

Peace, Dan

Dan
+ for the link, very interesting read
Zsolt Török
While we're talking about task killers, a very enlightening post appeared on the Android reddit a couple of days ago. The gist is, use task killers carefully or you could actually end up hurting your battery life: http://www.reddit.com/r/Android/comments/cwhm6/i_stopped_using_a_task_killer_last_week_to_see_if/
Neil Traft
@Neil Traft, I found the comments on the post very enlightening. Sales reps in the stores are recommending and installing task killers for their customers :)
dipu
A: 

I hope things will change over time. User should be able to kill an app or process if the app process is sandboxed correctly by the OS. There is a notion that apps should be written perfectly or user will use only the apps that follow all SDK recommendation. I think that is a tall order. It reminds me of absence of delete button in gmail.

dipu
A: 

without exit function for application developer to kill their own application is very bad design. My application needs to allow user to dynamic change data dynamic during runtime and user need to restart my application to make the change effect but android did not allow my application restart by itself. Android OS has very bad design application life cycle.

vgps
+1  A: 

This is an interesting and insightful discussion with so many experts contributing. I feel this post should be looped back from within the android dev main website because it does revolve around one of the core designs of android OS.

I would also like to add my 2 cents here.

So far I have been impressed with Android's way of handling lifecycle events, bringing the concept of web like experience to native apps.

Having said that I still believe that there should be a Quit button. Why .. not for me or ted or any of the tech gurus here but for the sole purpose of meeting an end user demand.

Though I am not a big fan of Windows but long back they introduced a concept that most end users are comfortable with and we as developers have to live with that whether we like it or not ... "I want to quit running a widget when 'I' want to". That does not mean someone (OS, developer ?) will take care of that at its/his/her own descretion... it simply means "where is my Red X button that I am used to". My action should be analogous to 'end a call on press of a button', 'turn off the device by pressing a button' so on and so forth ... it's a perception. It brings a satisfaction per se that my action indeed achieve its purpose.

Even though a developer can spoof this behavior using suggestions given here the perception still remains i.e. an application should completely cease to function (Now), by an independent, trusted and neutral source (OS) on demand from the end user.

Paul
I don't understand the downvote. Although I disagree with the conclusion, I think this argument is as valid as any.
Zsolt Török
Dont get the downvote either... So I give a upvote =)
Ted