0
我已創建服務UploadData
,其中觸發開始同步事件。在那裏添加編碼來安排在晚上9點運行的服務,運行1小時的時間間隔,運行得非常好。只有時間表服務n沒有。定期計時之間的時間間隔[早上9點至中午12點]
ServiceAlarm.startServiceAlarm();
代碼片段:
public class ServiceAlarm {
public static AlarmManager alarmMgr;
public static PendingIntent alarmIntent;
static Context context;
public static void startServiceAlarm()
{
context = MyApplication.getApplication();
alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(SmartConsultant.getApplication(), UploadData.class);
alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
// Set the alarm to start at 9:00 a.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 21);
calendar.set(Calendar.MINUTE, 00);
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_HOUR, alarmIntent);
Log.i("Service", "Service Started!");
}
public static void stopServiceAlarm()
{
alarmMgr.cancel(alarmIntent);
}
}
但我希望這些服務關機上午12:00後[它必須在每天下午9:00之間只運行三次到12:00 AM]。
如何在上午12:00停止相同的服務?
感謝您的承認。我已經發射另一個報警,取消了之前的報警。但仍然沒有測試它。手指交叉。 –