简体   繁体   English

一段时间后,android活动中的broadcastreceiver没有接收到意图

[英]broadcastreceiver within android activity is not receiving intents after a while

i am a beginner to android..i am facing the below issue.... Problem : broadcastreceiver within android activity is not receiving intents after receiving NETWORK_STATE_CHANGED_ACTION within a service started from that main activity.. 我是android的初学者。.i面临以下问题。...问题:在从该主要活动启动的服务中接收到NETWORK_STATE_CHANGED_ACTION后,android活动中的broadcastreceiver没有收到意图。

More details: i have an activity and an intentservice in my application.i invoke the service from the onCreate() method of the activity. 更多详细信息:我的应用程序中有一个活动和一个intentservice.i从活动的onCreate()方法调用该服务。 communication between the service and the activity is via a broadcastreceiver in the activity which receives the intent(say UIintent) i send from the service...this intent is basically to update the user interface based on the status available in my service.... 服务和活动之间的通信是通过活动中的广播接收器接收的,该活动接收我从服务中发送的意图(例如UIintent)...该意图基本上是根据我的服务中可用的状态来更新用户界面... 。

my activity is able to receive the intent(UIintent) broadcast from the service until a certain point of time.after that my intent(UIintent) is not received in the activity. 在某个时间点之前,我的活动能够接收来自服务的意图(UIintent)广播。此后,活动中未接收到我的意图(UIintent)。

I have registered for NETWORK_STATE_CHANGED_ACTION within my service. 我已经在我的服务中注册了NETWORK_STATE_CHANGED_ACTION。 The point after which my activity is not receiving the intent(UIintent) is when the service receives the NETWORK_STATE_CHANGED_ACTION intent. 服务没有收到NETWORK_STATE_CHANGED_ACTION意图后,我的活动没有收到意图(UIintent)。

Registering for the UIintent in my activity is done within the oncreate() itself. 在我的活动中注册UIintent是在oncreate()本身内完成的。 I also tried unregistering in onPause() and registering it again in onResume() still in vain.Can someone help me in resolving this issue. 我还尝试了在onPause()中注销并再次在onResume()中仍然无效地进行注册。有人可以帮助我解决此问题。 All the broadcast receivers are registered in code and not in xml. 所有广播接收器均以代码而非xml进行注册。

Try out intent filters if you are not using any, they shield the Broadcast Receiver from intent which you do not wish to process. 如果您不使用Intent过滤器,请尝试使用Intent过滤器,它们可以使Broadcast Receiver免受您不希望处理的Intent的影响。 Intent filters have to be applied on both the broadcast intent and the broadcast receiver. 意图过滤器必须同时应用于广播意图和广播接收器。

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

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