BroadcatReceiver declared in manifest.xml not receiving LocalBroadcastManager intents

早过忘川 提交于 2019-12-22 04:43:46

问题


While it is possible to declare a 'Local' BroadcastReceiver via code so it receives intents published via a LocalBroadcastManager.Ex

LocalBroadcastManager.getInstance(this).registerReceiver(new FooReceiver(), new IntentFilter("foo_intent_filter"));

I wonder if it is possible to declare such receiver via the manifest.xml (cleaner) .

When I use the 'manifest way', the receiver is not 'receiving' the intents.

  <receiver
        android:name="FooReceiver"
        android:enabled="true"
        android:exported="false" >
        <intent-filter>
            <action android:name="foo_intent_filter" />
        </intent-filter>
  </receiver>

Am I missing something? or the code-way is the only viable solution.

Thanks


回答1:


I wonder if it is possible to declare such receiver via the manifest.xml (cleaner) .

First, that is not possible.

Second, registering in the manifest has little to do with it being "cleaner". It is to allow Android to instantiate the receiver on its own, so that you can respond to broadcasts when your process is not running. And, in the specific example that you cite, it is to allow any app on the system to send you a broadcast. Neither of those are relevant for LocalBroadcastManager.



来源:https://stackoverflow.com/questions/24081676/broadcatreceiver-declared-in-manifest-xml-not-receiving-localbroadcastmanager-in

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