comead
comead

Reputation: 577

Android Service Keeps Getting Killed?

I am currently writing an app that allows a parent to log the events that occurs from their childs phone. The logging takes place in a service which runs in the background. However, the service keeps dying after around a minute..

I dont know what other information you need to help, but any information is useful!

Thanks!

Upvotes: 2

Views: 3235

Answers (2)

Nikola Despotoski
Nikola Despotoski

Reputation: 50538

If you are just binding to the service, then that's why your service is killed when the activity unbinds (Read that in the Docs). If you are using .startService() and then bind make sure in the onStartCommand() you return START_STICKY. You can read why and how here

http://developer.android.com/reference/android/app/Service.html#START_STICKY

And yes, use .startForground() as well if you are doing something that user is aware of and shouldn't be killed in extreme cases.

Upvotes: 3

zapl
zapl

Reputation: 63945

try starting the Service as foreground.

Reasons why a Service gets killed are here

Upvotes: 0

Related Questions