1

I have a question about the exit button. I have read several posts on here about use of an exit button/back button. Also the blog: http://blog.radioactiveyak.com/2010/05/when-to-include-exit-button-in-android.html, which clears discourages the use of an exit button.

Here is my question. I have an app that is very small; however it pulls data from the webservice/MySql database online. It is supposed to only pull data on first open. Or, if the user selects update data from a menu. I do not have an exit button in the app, However I thought that if the user would back completely out of the app, this would be the same as an EXIT.

After backing out of the app, I can still see the app in Setting>Applications>Running Services. It says "1 process and 1 service". In Manage Applicaions, it says that the app has been running for 36 hours. Is this okay? I do not want users to think my app is using their battery. On a separate note, I do not see an additional updating (pull from webservice) after backing out. But if I install the app on my galaxy Tablet 10.1 running Android 3.1, I do see an occasional update from the webservice.

Anyone have some advice for me?

5 Answers 5

4

Android won't stop an application when the user presses "back". The application will stay on memory until Android needs the memory for another application. Any thread that was running when the user presses "back" will continue to run. Traditionally, you're supposed to stop all those processes on the onPause() method of your Activity (additionally, store all preferences and other cleanup.)

Also, if you've started a Service (as stated), then it will continue to run until you tell it to stop. On rare occasions, Android will kill a Service to free up resources, but for the most part you have to kill it.

2
  • Thank you. We will end the service after update! (As soon as qwe figure out how! lol) Thanks again! Sep 12, 2011 at 14:36
  • Since you said this was a one-time call, you may consider doing an AsyncTask. Service are generally used for background operations that happen when an Activity is not in use (such as saving GPS coordinates to a file). AsyncTasks are one-time threads that are meant for convenient threading. Just a suggestion though. developer.android.com/reference/android/os/AsyncTask.html
    – DeeV
    Sep 12, 2011 at 14:56
0

As you mentioned it is showing 1 service running. So you need to stop this service and release the resource if any you have used in the service as android will not do it for you.

2
  • So, I need to stop the webservice? And then the app will not show up in teh settings? Sep 12, 2011 at 13:49
  • Exit means no part of your app should be active ... all threads, services should be destroyed.. Sep 12, 2011 at 13:53
0

If you're only downloading the information with the webservice on startup and then manually, why not just stop the service, once its downloaded the data and then start it again when the user has requested a manual refresh?

Android rarely kills a service in Android, however will (whenever it wants) stop your application from running in memory. BUT with how the Android handles activities, your app will likely be started again from the last activity window it was in.

0

After backing out of the app, I can still see the app in Setting>Applications>Running Services. It says "1 process and 1 service".

This means you started a service and never stopped it. For an operation like the one you describe, perhaps you should be using an IntentService, which automatically shuts down when the work is complete.

Is this okay?

It is certainly not ideal. Some users get very irritated with apps that behave like yours, using task killers or the Manage Services screen in Settings to force-stop your app.

1
  • Thank you. I will end the service. And hopefully the app will not stay in running. Sep 12, 2011 at 14:27
0

First create a button and place this code onClick event

System.runFinalizersOnExit(true);
System.exit(0);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.