I'm doing an data usage app but I'm having some troubles. Basically I'm doing what's described here, in the accepted answer, but some other problems come to my mind. For example, if the user kills the app, the service that updates the database is also destroyed and be consequence the app will stop storing the data. So my question is how can I work around this problem? Is there a way to start the service again or to keep it running even if the user kills the app? Is there any other solution?
Asked
Active
Viewed 33 times
1 Answers
1
If you want to restart your service automatically after being killed by another process, you can use following constants in your service,
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}

Simar
- 600
- 4
- 17
-
And this will restart the service every time that it's killed? By this I mean by the user in the task manager or the system itself. – Nuno Jan 06 '15 at 17:42
-
I am not sure about the system kill. – Simar Jan 06 '15 at 17:46
-
hmm thanks. I will try to check that. In the meantime lets wait for others answers. If I found out that this solution worked I will accept you answer later – Nuno Jan 06 '15 at 18:05