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
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);
}