Note that there are some explanatory texts on larger screens.

plurals
  1. POTimeout in BroadcastReceivers using IntentServices
    text
    copied!<p>I've got two services running. They do their work and then reschedule themselves via the AlarmManager. In the BroadcastReceiver the only thing that happens is the launching of the service via Context.startService(). Both services are IntentServices, which as far as I can tell shouldn't be causing timeout problems. I've tried IntentServices, threading, and AsyncTasks but am repeatedly bumping up against the timeout error in the receivers themselves.</p> <p>The timeout message is: 01-18 11:29:04.200: WARN/ActivityManager(73): Timeout of broadcast BroadcastRecord{433a4168 my.package.action.a} - receiver=android.os.BinderProxy@43399978 01-18 11:29:04.210: WARN/ActivityManager(73): Receiver during timeout: ResolveInfo{43394a30 my.package.MyReceiverA p=0 o=0 m=0x108000}</p> <p>The basic structure of the two receivers:</p> <pre><code>public class MyReceiverA extends BroadcastReceiver { public static final String ACTION_TO_BROADCAST = "my.package.action.a"; public void onReceive(Context context, Intent intent) { // start the service Intent serviceIntent = new Intent().setClassName(context, MyServiceA.class.getName()); context.startService(serviceIntent); } } </code></pre> <p>And the services:</p> <p>public class MyServiceA extends IntentService { public ActivityMonitorService() { super(TAG); }</p> <pre><code>public IBinder onBind(Intent intent) { // We don't allow anyone to bind to us return null; } public void onCreate() { super.onCreate(); _context = getApplicationContext(); _config = new Config(); if (_handler == null) { _handler = new Handler(); } } /** * Schedules an alarm to run ourselves again after ALARM_INTERVAL has passed. */ private void reschedule() { Intent intent = new Intent(MyReceiverA.ACTION_TO_BROADCAST); PendingIntent pendingIntent = PendingIntent.getBroadcast(_context, 0, intent, 0); AlarmManager manager = (AlarmManager) _context.getSystemService(Context.ALARM_SERVICE); manager.set(AlarmManager.RTC, now + delay, pendingIntent); } private void doWork() { // Do some work. This could take a while. It also accesses a database that the two // services share through synchronized blocks of code in static accessor functions. } protected void onHandleIntent(Intent intent) { try { doWork(); } catch (Exception e) { // log it } finally { reschedule(); } } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload