1
我想爲10:00 AM to 8:00 PM
運行服務類,我嘗試了AlarmManager
但它運行不正常,我該怎麼做?運行特定時間段的後臺服務
中的任何一個,請幫助me.`
public void alrammanager(){
Log.d(TAG, "onStartCommand");
Toast.makeText(HomePage.this, "alarm manager start", Toast.LENGTH_LONG).show();
alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, MyService.class);
alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
// Set the alarm to start at 8:30 a.m.
calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 10);
calendar.set(Calendar.MINUTE, 00);
// setRepeating() lets you specify a precise custom interval--in this case, // 20 minutes.
int secondsreperts = 30;
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
secondsreperts * 1000, alarmIntent);
}
問題並不清楚。到目前爲止,你已經嘗試過。只需發佈你的不工作代碼。 – RameshJaga