我盲目地关注这篇基于共同软件的唤醒意图服务的帖子,但是服务从未在第二天被解雇。我猜问题就在于getMaxAge()。 下面是我的dailY听众的代码。
public class DailyListener implements AlarmListener {
public void scheduleAlarms(AlarmManager mgr, PendingIntent pi, Context context) {
// every day at scheduled time
Calendar calendar = Calendar.getInstance();
// if it's after or equal 9 am schedule for next day
if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) >= 9) {
calendar.add(Calendar.DAY_OF_YEAR, 1);
}
calendar.set(Calendar.HOUR_OF_DAY, 9);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
mgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pi);
//mgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),2 * 60 * 1000, pi);
}
public void sendWakefulWork(Context context) {
if(Util.haveNetworkConnection(context))
{
Intent backgroundIntent = new Intent(context, PushLogDataService.class);
WakefulIntentService.sendWakefulWork(context, backgroundIntent);
} else {
Log.d("DailyListener", "We have no internet, enable ConnectivityReceiver!");
// enable receiver to schedule update when internet is available!
ConnectivityReceiver.enableReceiver(context);
}
}
public long getMaxAge() {
return (AlarmManager.INTERVAL_DAY + 60 * 1000);
}
}