BroadCast Receiver Active only when activity is running else deactivated

假如想象 提交于 2019-12-06 09:45:12

If you want this works in background then, You need to add broadcast receiver in manifest file with Broadcast receiver class.

like this tutorial http://www.vogella.com/articles/AndroidBroadcastReceiver/article.html

You can use your own "MyReceiver".

Here in this case you dont need to register and unregistered. This will work automatically.

if you want your broadcast receiver to run all teh time, yu need to register it from manifest file. from documentation: You can either dynamically register an instance of this class with Context.registerReceiver() or statically publish an implementation through the tag in your AndroidManifest.xml.

http://developer.android.com/reference/android/content/BroadcastReceiver.html

First of you are defined mainfest so app also not running they broadcast receiver work.. so you can handle this type of broadcast using a PackageManager and get package name if is enable or disable you can check and run your brodcast

i think Service class will help you , try to implement .... in background for infinity times and when ever your service will find that something is changed then it will send some broadcast . to you :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!