BroadcastReceiver 无法在 Android 3.0 上运行
我有一个插件框架,它使用广播意图在主应用程序和插件之间进行通信。启动时主应用程序发送广播意图
sendBroadcast(new Intent("com.mypackage.myapp.custom.intent.action.ADDON_REQ"));
每个插件应用程序都有一个在其清单文件中注册的广播接收器。
<receiver
android:name="IncomingReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.mypackage.myapp.custom.intent.action.ADDON_REQ" >
</action>
</intent-filter>
</receiver>
插件应用程序没有定义任何活动。该框架在所有低于 3.0 的 Android 版本上都能正常运行。从 Honeycomb 开始,插件中的广播接收器永远不会被调用。 直到我在插件应用程序中添加主要活动之前,我无法解决此问题。通过清单中定义的活动,现有广播接收器开始接收广播消息。这种行为的可能原因是什么?有什么办法可以在不添加活动的情况下解决这个问题吗?
谢谢
I have a plugin framework which uses broadcast intents for communication between main application and plugins. On start main app sends a broadcast intent
sendBroadcast(new Intent("com.mypackage.myapp.custom.intent.action.ADDON_REQ"));
Each plugin app has a broadcast receiver registered in its manifest file.
<receiver
android:name="IncomingReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.mypackage.myapp.custom.intent.action.ADDON_REQ" >
</action>
</intent-filter>
</receiver>
Plugin application does not have any activities defined. This framework works fine on all Android versions lower that 3.0. Starting from Honeycomb the broadcast receiver in plugin is never called.
I could not fix this until I added a main activity in the plugin app. With the activity defined in manifest existing broadcast receiver started to receive broadcast messages. What is the possible reason for such behavior? Is there any way to fix this without adding activity?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 honeycomb 开始,如果接收应用程序尚未运行,您需要指定一个标志来启动它: Intent.FLAG_INCLUDE_STOPPED_PACKAGES。
From honeycomb onward you need to specify a flag to start the receiving app if it's not already running: Intent.FLAG_INCLUDE_STOPPED_PACKAGES.