restart service reboot android code example

Example: restart service ondestroy android

AppLog.i("System UI Service is Restarting")
        val startSystemUiIntent = Intent(context, AwesomeService::class.java)
        val restartServicePendingIntent = PendingIntent.getService(context, 1, startSystemUiIntent, PendingIntent.FLAG_ONE_SHOT)

        val alarmManager = getSystemService(ALARM_SERVICE) as AlarmManager
        alarmManager.setExact(AlarmManager.RTC_WAKEUP, SystemClock.currentThreadTimeMillis(), restartServicePendingIntent)


        stopService(Intent(context, SystemUIService::class.java))

Tags:

Misc Example