0
我安排一個報警經理是這樣的:默認值開始服務
Intent myIntent = new Intent(context, Locale.class);
intent.putExtra("end",AlarmEnd.getTimeInMillis());
PendingIntent pendingIntent = PendingIntent.getService(context, 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, AlarmStart.getTimeInMillis(), 40 * 1000, pendingIntent);
這樣的工作...問題是,當它開始地點
public int onStartCommand(Intent intent, int flags, int startId) {
int t = START_STICKY;
SharedPreferences alarms = getApplicationContext().getSharedPreferences("alarms", 0);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Log.i("LocalService", "Received start id " + startId + ": " + intent);
client = new AsyncHttpClient();
endTime = intent.getLongExtra("end",0);
Log.d("Alarms", "End time is".concat(endTime.toString()));
的調試消息始終輸出默認值「結束時間爲0」..我知道額外的意圖不是零(檢查它)。我究竟做錯了什麼?
當與服務直接使用時,_WAKEUP報警不可靠。請將它們與'BroadcastReceiver'一起使用,或者與我的'WakefulIntentService'或您自己的'IntentService' /'WakeLock'組合搭配使用。關於你的問題,試試'FLAG_UPDATE_CURRENT'而不是'FLAG_CANCEL_CURRENT',看看是否有幫助。 – CommonsWare
似乎工作非常可靠..但是我一定會考慮它..更改爲UPDATE_CURRENT沒有效果。 – Michael
「似乎工作非常可靠」 - 它偶爾會失敗,因爲在服務有機會運行之前設備就會重新入睡,更不用說獲取「WakeLock」了。 – CommonsWare