這是我正在努力完成並嚴重失敗。服務和報警管理器
我需要:
-start服務
待辦事宜一些任務
-set AlarmManager的時間
設定時間 - 停止服務後重新啓動該服務
我遇到的問題是服務幾乎立即停止重新啓動。我要的是,警報響起後,服務應該啓動..
下面是代碼: -
Intent intent = new Intent(ThisService.this,
ThisService.class);
PendingIntent pendingIntent = PendingIntent.getService(ThisService.this, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
alarmManager.cancel(pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
getUpdateTime(), getUpdateTime(), pendingIntent);
stopSelf();
代碼在哪裏?在爲第一個服務使用完成一些任務後,在此處添加 –
** stopService()**將意向傳遞給您的服務類,然後在服務停止後,您可以創建一個警報管理器實例並在一段時間後再次啓動服務 檢查這也是http://developer.android.com/reference/android/content/Context.html#stopService(android.content.Intent) –
我只是想停止當前的服務,並讓AlarmManager之後再次創建相同的服務時間 – d3m0li5h3r