Reputation: 5166
I have a service doing some background job that should continue running as long as until some particular condition within my app changes. I have used the START_STICKY flag.
However, the Android system will still terminate the service if it requires resources.
I thought of a work-around. I thought of calling the startService method from the onDestroy method (based on an internal condition being met in my app) so that when the android service terminates this service, it will restart if required by my app.
Will this work? Is this harmful to the device in any way?
Upvotes: 1
Views: 103
Reputation: 4192
A service running all the time == fast battery drainage
no matter what... I suggest you change your design, i.e use a BroadcastReceiver
in your app to listen for call state changes, when call state changes your application will catch the broadcast then you can do anything during/after call.
You can then start a service from broadcast receiver.. which should perform the tasks you need for example, call state changes, broadcast is fired, your application gets it, you then check whats the call state, if its on call, then start your service.. then when call disconnects another broadcast will be fired by the system, your application will get it then you'll check the call state again, if its disconnected then stop the service. Hope you're getting me here.
Upvotes: 1