-3
我有一個報警管理器,每1分鐘後調用一次特定的服務進行一些計算並向廣播接收器發送廣播。我使用警報管理器setRepeating()完成了此操作。報警管理器在重新啓動後沒有調用服務
這我的代碼:
報警經理:
Intent serviceIntent = new Intent(this, PrayerNotifyService.class);
PendingIntent pintent = PendingIntent.getService(this, 0, serviceIntent, 0);
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 60000, pintent);
它工作正常,但重啓手機後,警報管理器不調用服務。
我在互聯網上搜索,發現像下面的一些解決方案,但他們沒有爲我工作。
我也給啓動完成許可
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
我在清單接收器:
<receiver
android:name=".NotificationReceiver"
android:enabled="true"
android:exported="true" >
<action android:name="android.intent.action.BOOT_COMPLETED" />
</receiver>
任何一個可以告訴我怎麼解決這個問題呢?
當設備關閉時,定製報警會被破壞,每當設備啓動時,您都需要重新註冊報警。檢查這個問題http://stackoverflow.com/q/12034357/5505915 – Arjun
Ca你告訴我在每一分鐘之後在後臺工作的正確方法嗎?我不想使用始終運行的粘性服務 –
@asadhaider恕我直言,你不應該在如此低的頻率使用警報。在這種情況下最好使用Timer。每分鐘設置一次鬧鐘的目的是什麼? – iZBasit