Skip to content

Instantly share code, notes, and snippets.

@robertohuertasm
Created September 29, 2020 19:46
Show Gist options
  • Save robertohuertasm/96e3c49470d7793ba08ce962e975aa93 to your computer and use it in GitHub Desktop.
Save robertohuertasm/96e3c49470d7793ba08ce962e975aa93 to your computer and use it in GitHub Desktop.
override fun onTaskRemoved(rootIntent: Intent) {
val restartServiceIntent = Intent(applicationContext, EndlessService::class.java).also {
it.setPackage(packageName)
};
val restartServicePendingIntent: PendingIntent = PendingIntent.getService(this, 1, restartServiceIntent, PendingIntent.FLAG_ONE_SHOT);
applicationContext.getSystemService(Context.ALARM_SERVICE);
val alarmService: AlarmManager = applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager;
alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, restartServicePendingIntent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment