Reputation: 347
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?
Upvotes: 1
Views: 2511
Reputation: 1372
First create a button and place this code onClick event
System.runFinalizersOnExit(true);
System.exit(0);
Upvotes: 0
Reputation: 1007534
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.
Upvotes: 0
Reputation: 14331
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.
Upvotes: 0
Reputation: 36045
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.
Upvotes: 4
Reputation: 24031
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.
Upvotes: 0