Service Crashes On 'death' Of Activity
Solution 1:
The provided answers didn't help me. But I found a really easy way to do this, add in the Manifest
<serviceandroid:name="..."android:process=":remote" />
http://developer.android.com/guide/topics/manifest/service-element.html
Just testing at the moment, my Activity got already killed, but my service is running.
Solution 2:
When I run the app, and go back to the homescreen, the Service keeps running. But after a while I get these logcat messages, and the service stops... How can I prevent this?
You don't, generally speaking.
Services are not designed to run forever. Too many developers have started services and never stopped them. And, in your case, they do so for no good reason. Having a service hang around in memory just watching the clock tick is wasteful, and it is particularly because developers do things like this that Android "crashes" services after they stick around too long.
In your case, please switch to use AlarmManager
, probably in conjunction with an IntentService
, so the service shuts down on its own accord when there is no more work to be done.
Solution 3:
You will want to look at having your service run as a Remote Service
, so that it runs in its own process.
A blog about remote services: http://saigeethamn.blogspot.com/2009/09/android-developer-tutorial-part-9.html
An example of a sample one: http://about-android.blogspot.com/2010/02/android-remote-service-sample.html
Post a Comment for "Service Crashes On 'death' Of Activity"