Restart service after force stop

后端 未结 3 819
时光取名叫无心
时光取名叫无心 2020-12-06 12:48

I am developing an application which is used as application locker, an app which is able to protect other installed apps by asking the user for a password on opening those a

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-06 12:55

    I solved this problem by scheduling AlarmManager, to run my service again:

        public void onDestroy() {
            AlarmManager alarmMgr = (AlarmManager)this.getSystemService(this.ALARM_SERVICE);
            Intent i = new Intent(this, MyService.class);
            PendingIntent pendingIntent = PendingIntent.getService(this, 0, i, 0);
            alarmMgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10, pendingIntent);
        }
    

提交回复
热议问题