Android服务onTaskRemoved()不在Device上调用,但适用于Emulator Genymotion

时间:2016-12-16 08:23:09

标签: android

Android服务onTaskRemoved()未在Device上调用,但适用于Emulator Genymotion

 @Override
public void onTaskRemoved(Intent rootIntent) {

    Toast.makeText(getBaseContext(), "TASK ON REMOVE ", Toast.LENGTH_LONG).show();
    Intent restartServiceIntent = new Intent(getApplicationContext(),
            this.getClass());
    restartServiceIntent.setPackage(getPackageName());

    PendingIntent restartServicePendingIntent = PendingIntent.getService(
            getApplicationContext(), 1, restartServiceIntent,
            PendingIntent.FLAG_ONE_SHOT);
    AlarmManager alarmService = (AlarmManager) getApplicationContext()
            .getSystemService(Context.ALARM_SERVICE);
    alarmService.set(AlarmManager.ELAPSED_REALTIME,
            SystemClock.elapsedRealtime() + 1000,
            restartServicePendingIntent);

    super.onTaskRemoved(rootIntent);
}

Emulator Genymotion Android 6.0,设备华为android 6.0

帮帮我。谢谢。

0 个答案:

没有答案