I have a service that should run in background.
I have applied solution from given link
START_STICKY does not work on Android KitKat
I am able to restart the service on all phones having android os jelly bean or kitkat.
But on Redmi (android os version 4.3) phone my service is still getting killed when I remove app from task manager and not restart again. How can I restart my service on Redmi phone.
I tried to restart service using AlarmManager.
private void StartLocationServiceByAlarmManager() {
Calendar cur_cal = Calendar.getInstance();
cur_cal.setTimeInMillis(System.currentTimeMillis());
cur_cal.add(Calendar.SECOND, 50);
long backgroundServiceUpdateInterval = 0;
Interval = 3 * 60 * 1000; // xyz
// stopService(new Intent(this,cl));
// Background sync service
Intent mServiceIntent = new Intent(this, cl);
mServiceIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
PendingIntent pintent = PendingIntent.getService(this, 121,
mServiceIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cur_cal.getTimeInMillis(),
Interval, pintent);
}