In android 4.4, swiping app out of recent tasks permanently kills application with its service . Any idea why?

Got it. Its a bug in 4.4. I tried this and it worked perfectly fine(its a dirty workout though).

Just override this method -:

public void onTaskRemoved(Intent rootIntent) {
    Log.e("FLAGX : ", ServiceInfo.FLAG_STOP_WITH_TASK + "");
    Intent restartServiceIntent = new Intent(getApplicationContext(),
            this.getClass());
    restartServiceIntent.setPackage(getPackageName());

    PendingIntent restartServicePendingIntent = PendingIntent.getService(
            getApplicationContext(), 1, restartServiceIntent,
            PendingIntent.FLAG_ONE_SHOT);
    AlarmManager alarmService = (AlarmManager) getApplicationContext()
            .getSystemService(Context.ALARM_SERVICE);
    alarmService.set(AlarmManager.ELAPSED_REALTIME,
            SystemClock.elapsedRealtime() + 1000,
            restartServicePendingIntent);

    super.onTaskRemoved(rootIntent);
}

Leave a Comment