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