简体   繁体   中英

BroadcastReceiver from AlarmManager not receiving in child activities/intent

I have a problem that my BroadcastReciever set up to receive events from an AlarmManager is not being received in child activities started by the main activity. I don't know where to look. Sometimes if the child activity starts fast enough then the AlarmMananger never seems to send an event. I'm trying to trigger events weeks into the future but I can't even get seconds into the future working, only milliseconds do I get any back in onReceive() in BroadcastReciever (this is implemented in the Class NotifyAlarmReceiver)

My Manifest file has this:

<receiver android:name=".notifications.NotifyAlarmReceiver"></receiver>

I've tried using process and exported fields, but they don't seem to do anything.

And the code to setup the Alarm is:

Intent notifyReceiverIntent = new Intent(this, NotifyAlarmReceiver.class);
PendingIntent notifyPI = PendingIntent.getBroadcast(this, 0, notifyReceiverIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mAlarmManager.set(AlarmManager.RTC, timems, notifyPI);

Where should I look to now?

I would try programmatically registering and unregistering the receiver to see if that changes anything. Assuming you aren't forced to have a static receiver declared from your manifest. Your issue feels weird as it sounds like you're intents aren't persisting long enough to reach your receiver and possible the other way around. And i've always used the xml tag with the package name of the app on my receivers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM