I've created a custom Background Service, who is extending IntentService. I'm calling this class when my app goes to background via .startService(). Firsly onStartCommand is called where I'm returning START_STICKY (like I've read some other posts to keep my service alive and re-create if needed when is killed due to low memory). After that I'm implementing onHandleIntent(intent) method where I'm getting the extras from the caller intent and here I'm starting a Timer to run every minute and execute simple code. But the problem here is that, when the app is in background, after 30 mins my service is killed and not re-created. Here is part of my code, so any suggestions would be perfect.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
@Override
protected void onHandleIntent(Intent workIntent) {
//here I'm initializing the Timer
}
class UpdateTimeTask2 extends TimerTask {
public void run() {
backgroundTimer();//here I'm doing some simple coding
}
}