i have repeating service which runs every 5 minutes as long as the app is installed, but some times my service stops or gets killed, how do i make it fail safe and restart the service if it gets killed by the OS.
This is how im starting my repeating service.
Intent serviceIntent = new Intent(context, SyncService.class);
final AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long interval = 60000; // 5 Mins - 1000*60; 1 sec=1000, 1min sec = 60*1000=60000
final PendingIntent pending = PendingIntent.getService(context, 0, serviceIntent, 0);
alarm.setRepeating(AlarmManager.RTC ,System.currentTimeMillis(), interval, pending);
and this is my service:
public class SyncService extends IntentService {
public SyncService() {
super("SyncService");
// TODO Auto-generated constructor stub
}
@Override
protected void onHandleIntent(Intent intent) {
SyncToServer();
}
}