PaTw1
PaTw1

Reputation: 1

Keep android application running while in background

I have created an application in Android. This application should never die (even when sent to the background). Currently, after a while the Service manager returns "No longer want..." and terminates it. I've read that one solution whould be to create a service. However my application is way to complicated to be splitted into two functionality sets (one for the service and one for the application).

Is there any "trick" in order to keep my application running at all time? Could I create a dummy service inside my application that might force the android to keep my application alive? Is there any other way?

FYI: 1) It's a customized application that will not be released on the Market. 2) Handsets can't be rootted.

Thanks

Upvotes: 0

Views: 2591

Answers (1)

louielouie
louielouie

Reputation: 14941

You must create a Service to have a persistently running app, even after all your Activities have been sent to the background due to user pressing the Back button, answering a call, switching to another app, etc. You should review the Android Process Lifecycle which states that:

Sometimes an Activity may need to do a long-running operation that exists independently of the activity lifecycle itself. An example may be a camera application that allows you to upload a picture to a web site. The upload may take a long time, and the application should allow the user to leave the application will it is executing. To accomplish this, your Activity should start a Service in which the upload takes place. This allows the system to properly prioritize your process (considering it to be more important than other non-visible applications) for the duration of the upload, independent of whether the original activity is paused, stopped, or finished.

Upvotes: 1

Related Questions