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.

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}

The basic structure of the two receivers:

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);
    }
}

And the services:

    public class MyServiceA extends IntentService {
        public ActivityMonitorService() {
            super(TAG);
        }

        /**
         * 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();
        }
    }
}

What I don't understand is how the receivers are timing out. I
literally do nothing but check an if statement and then fire off an
intent to launch the service. It was my understanding that
IntentServices themselves will never time out. Is this not correct? Is
there another way I should be doing these receivers?

Thanks,
James

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to