are multiple broadcast receivers legal in android?

徘徊边缘 提交于 2019-12-21 12:27:08

问题


Is this true?

Only one BroadcastReceiver class can be specified per application. Should you need to incorporate two or more BroadcastReceivers from different SDKs, you will need to create your own BroadcastReceiver class that will receive all broadcasts and call the appropriate BroadcastReceivers for each type of Broadcast.

http://code.google.com/apis/analytics/docs/mobile/android.html#google-play-tracking

There is no mention of this in the manifest documentation for <receiver/>

http://developer.android.com/guide/topics/manifest/receiver-element.html


回答1:


The quoted passage is from the documentation for Google's mobile analytics package. It may be that Google's mobile analytics package cannot support more than one BroadcastReceiver for Google's mobile analytics package's broadcasts.

Android itself can most certainly have more than one BroadcastReceiver per application.




回答2:


The Android platform only delivers the install tracking intent to a single "receiver" for your application. What they mean is, if you are using two install trackers for your application you can not put two receivers containing the same action "com.android.vending.INSTALL_REFERRER". If this is the case, then you can add a meta-data tag like

<meta-data android:name="forward.1"  android:value="<other receiver's name>" />

to your receiver so both receivers receive the Intent.



来源:https://stackoverflow.com/questions/8013628/are-multiple-broadcast-receivers-legal-in-android

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