简体   繁体   English

活动Android中的广播接收器

[英]Broadcast receiver in activity Android

Is it possible that If I place some part of the code from my Activity in Broadcast and then even if the activity is not running the broadcasted piece of code will continue to work?If yes any reference to it plz? 如果我将我的活动中的部分代码放到广播中,然后即使该活动未运行,是否有可能继续播放该广播的代码? To b specific I've facebook activity that retrieves notifications on button click.I want that get notification method to b in a broadcast so that every time notification arrives it generates alert.Can provide the code aswel.. Kindly help 具体来说,我有一个Facebook活动,它会在单击按钮时检索通知。我希望广播中的通知方法能够在广播中出现,以便每次通知到达时都会生成警报。可以提供以下代码。

Is it possible that If I place some part of the code from my Activity in Broadcast and then even if the activity is not running the broadcasted piece of code will continue to work? 如果我将“活动”中的部分代码放在“广播”中,然后即使该活动未运行,则广播的代码片段是否仍可以继续工作?

No, it is not possible that your activity is not running and you defined your broadcast in the activity and you still want the broadcast to run that is within that activity. 不,您的活动不可能在运行,并且您在活动中定义了广播,而您仍然希望该活动中的广播能够运行。

Add the BroadCast Receiver in a Service class. 在服务类中添加BroadCast接收器。 register and unregister this broadcast receiver from onCreate() and onDestroy() methods respectively of Service class. 在Service类的onCreate()和onDestroy()方法中分别注册和注销此广播接收器。

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

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