AlarmManager
을 사용하여 미리 정의 된 시간에 작업을 실행하도록 예약하려고합니다. 이 AlarmManager
은 내 응용 프로그램에서 초기화되며 Broadcast
이벤트가 onReceive()
내부에서 수신 될 때 백그라운드에서 실행됩니다. 내 에 '15 분 후'라고 재 스케줄하려고하는 내부의 context.startService(webServiceIntent);
을 사용하여 서비스를 호출합니다. ; 그러나 어떤 이유로 그것은 작동하지 않습니다. 모든 작업을 수행하면 PendingIntent
이 중지됩니다.AlaramManager가 미리 정의 된 시간 후에 작업을 실행하도록 예약합니다
//Initiliazing AlarmManager from my app
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
pendingIntent = PendingIntent.getBroadcast(this, 0, getLocationPollerIntent(), 0);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), Constant.LOCATION_POLLING_PERIOD, pendingIntent);
//onReceive Method of BroadcastReceiver
@Override
public void onReceive(Context context, Intent intent) {
Intent webServiceIntent = new Intent(context, LocationNotificationService.class);
webServiceIntent.putExtra("UPDATED_LOCATION", loc);
context.startService(webServiceIntent);
}
//Inside LocationNotificationService to reschedule the PendingIntent - This PendingIntent never get called
protected void onHandleIntent(Intent intent) {
c.set(Calendar.HOUR_OF_DAY, 13);
c.set(Calendar.MINUTE, 35);
c.set(Calendar.SECOND, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, getLocationPollerIntent(), PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, c.getTimeInMillis(), Constant.LOCATION_POLLING_PERIOD, pendingIntent);
}
그래, 사실 AlarmManager.ELAPSED_REALTIME_WAKEUP을 AlarmManager.RTC로 바꿨습니다. 하지만 이제 문제는 wakefulIntentService 내부에 있습니다. PendingIntent.getBroadcast (this, 0, getLocationPollerIntent(), PendingIntent.FLAG_UPDATE_CURRENT); – Waqas
@Waqas : 그럼'getLocationPollerIntent()'는 여분의 것보다 다른 것 인 다른'Intent'를 리턴합니다. – CommonsWare
흠 보이는 활동 내에서 getApplicationContext()가 동일한/다른 값을 반환하는지,이 깨어있는 인 텐트 서비스에서 호출되었을 때 알 수 있습니까? 사이에 다른 값을 반환한다면이 아이디어를 둘 다 어떻게 동일하게 만들 수 있을지 생각해보십시오. – Waqas