如何在android kitkat中保持服务的活力?
你好,朋友们,我搜索了很多,但没有找到谷歌所做的服务变化,我需要保持我的服务活着如何在android kitkat中保持服务的活力?,android,android-4.4-kitkat,Android,Android 4.4 Kitkat,你好,朋友们,我搜索了很多,但没有找到谷歌所做的服务变化,我需要保持我的服务活着 @Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); return START_STICKY; } 但是它不会在android 4.4.2中重新启动服务。你知道吗?你可以在andr
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
但是它不会在android 4.4.2中重新启动服务。你知道吗?你可以在android kitkat中使用它,因为他们正在从后台清除进程
@Override
public void onTaskRemoved(Intent rootIntent) {
Intent restartService = new Intent(getApplicationContext(),
this.getClass());
restartService.setPackage(getPackageName());
PendingIntent restartServicePI = PendingIntent.getService(
getApplicationContext(), 1, restartService,
PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmService = (AlarmManager) getApplicationContext()
.getSystemService(Context.ALARM_SERVICE);
alarmService.set(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + 5000, restartServicePI);
}