停止使用警报管理器安排的IntentService

时间:2018-03-12 04:18:04

标签: java android

我正试图从手机的图库中获取所有照片,因此将它们设置为递归的壁纸。我正在使用报警管理器。我希望一旦我从最近的任务中删除我的应用程序就停止IntentService。但我无法做到这一点。

我的 WallpaperPreferenceActivity 是:

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context=getApplicationContext();
        Bundle extras = this.getIntent().getExtras();
        String s=context.getPackageName();
        Log.e("TAG",s);
        String Interval =" ";
        if ( extras != null ) {
            if ( extras.containsKey ( "Interval" ) ) {
                Interval = extras.getString("Interval");
                int i = Integer.valueOf(Interval);
                updateInterval= i * 1000;
                System.out.println("PeerID: " + Interval);
            } else {
                System.out.println("No Interval in extras");
                updateInterval=10000;
            }
        } else {
            System.out.println("No extras");
            updateInterval =10000;
        }
        // Create the intents
        intent = new Intent(WallpaperService.REFRESH_WALLPAPER);
        pendingIntent = PendingIntent.getService(WallpaperPreferencesActivity.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

        // Schedule the alarm!
        long firstTime = SystemClock.elapsedRealtime();
        am = (AlarmManager) getSystemService(ALARM_SERVICE);

            Long refreshIntervalMs = updateInterval;
            Log.d("refreshIntervalMs", refreshIntervalMs.toString());
            // Schedule the alarm
            am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, firstTime, refreshIntervalMs, pendingIntent);

    }

    protected void onDestroy() {
        super.onDestroy();
        System.exit(0);
        Log.e("TAG","STOPPED");
    }

当有人从最近的任务中移除应用程序时,有人可以告诉我如何停止服务?

0 个答案:

没有答案