简体   繁体   English

来自AlarmManager的BroadcastReceiver在子活动/意图中未接收

[英]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. 我有一个问题,在主活动启动的子活动中,未接收到设置为从AlarmManager接收事件的BroadcastReciever。 I don't know where to look. 我不知道在哪里看。 Sometimes if the child activity starts fast enough then the AlarmMananger never seems to send an event. 有时,如果子活动开始得足够快,则AlarmMananger似乎永远不会发送事件。 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) 我试图在未来几周内触发事件,但我什至无法在未来几秒钟内触发事件,只有几毫秒的时间,我才能在BroadcastReciever的onReceive()中得到任何回报(这是在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. 而且我一直在接收器上使用xml标签和应用程序的软件包名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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