0
毎分X分ごとにいくつかのタスクを実行したい。私はAlarmManager
を使用しています。アプリが実行中またはバックグラウンドで正常に動作しています。ただし、アプリを実行しているアプリを削除した後は機能しなくなります。アプリが閉じているときにAlarmManagerが機能しない
アラーム設定:manifest.xmlに
Intent intent = new Intent(context , SoundNotificationReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0 , intent, 0);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Calendar c = Calendar.getInstance();
c.add(Calendar.MINUTE , 15);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, c.getTimeInMillis() , pendingIntent);
}
else {
alarmManager.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis() , pendingIntent);
}
System.out.println("Alarm is set : " + c.getTime());
:私はあなたが私を理解欠場と思う
<receiver android:name="info_tech.com.fazeker.SoundNotificationReceiver"
android:exported="true"
android:enabled="true">
</receiver>
は、 私の問題は、アプリケーションは、その後 – Ali
を閉じているときに、スケジュールアラームは動作しませんですonDestroy()には で使用してください –