Blocking AlarmManager at service startup

Android AlarmManager Javadoc Status

When an alarm goes off, the Intent that had been registered for it is broadcast by the system,

The demos of the APIs shipped with Android have AlarmService (package com.example.android.apis.app) that demonstrate the use of AlarmService.

In it we have the following (edited for clarity):

 PendingIntent mAlarmSender = PendingIntent.getService(AlarmService.this, 0, new Intent(AlarmService.this, AlarmService_Service.class), 0); AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 30*1000, mAlarmSender); 

So, in this example, it does not do PendingIntent mAlarmSender = PendingIntent.getBroadcast(...); , but does getService , which Javadoc never refers to.

The reason I'm asking about this is due to the consequences of blocking processor tracking. Javadoc says that the AlarmManger lock will be released after the onReceive() repeater onReceive() .

What interests me is what are the consequences of tracking blocking if you use Alarm, as in the example? Javadok does not seem to address this. If something seems like you should use the broadcast technique when setting up alarms.

+8
android alarmmanager android-wake-lock
source share
1 answer

What interests me is what are the consequences of tracking blocking if you use Alarm, as in the example?

There is no guarantee that your service will gain control before the device falls asleep.

If something seems like you should use the broadcast technique when setting up alarms.

For _WAKEUP alarms, yes, because this is the only way we guarantee control while the device is still not working.

Since the work performed by the _WAKEUP alarm tends to go beyond what you can safely do in the onReceive() registered BroadcastReceiver manifest, a common template is to delegate work to the IntentService . To this end, I packaged a WakefulIntentService to implement a template for securely managing an IntentService control and for a long time supporting the device enough for the service to do its job.

+6
source share

All Articles