开发者

Can I register more than one BroadcastReceiver for an Activity in an Android Programming?

开发者 https://www.devze.com 2023-04-10 09:21 出处:网络
I implemented a sample application which Shows the Phone Information, Battery Information of an Android application. I created two different Class files for two activities.

I implemented a sample application which Shows the Phone Information, Battery Information of an Android application. I created two different Class files for two activities.

There is no issue in getting the phone related information. There is an issue in getting the Battery related information on my phone. The following are the some of the expected Actions that I want to register.

Intent.ACTION_BATTERY_CHANGED
Intent.ACTION_UMS_CONNECTED
Intent.ACTION_UMS_DISCONNECTED
Intent.ACTION_POWER_CONNECTED
Intent.ACTION_POWER_DISCONNECTED

Case 1 - I registered multiple BroadcastReceivers for each of the action given above. Result - Only ACTION_BATTERY_CHANGED action data is coming up fine. But the other actions related data is not coming up fine.

Case 2 开发者_运维技巧- I registered only one BroadcastReceiver for ACTION_BATTERY_CHANGED. In the implementation of onReceive(Context context, Intent intent) method I am checking for the other actions (ACTION_UMS_CONNECTED, ACTION_UMS_DISCONNECTED, ACTION_POWER_CONNECTED, ACTION_POWER_DISCONNECTED)

Result - Still the same issue the other actions related information is not coming up fine.

I tested with my Android Phone which has Android 2.1 update-1 version.


Can I register more than one BroadcastReceiver for an Activity in an Android Programming?

AFAIK, yes. Moreover, you do not necessarily need multiple BroadcastReceiver objects for your scenario -- you could create a single IntentFilter that lists all your desired actions (see the addAction() method).

Rest of all are error data

That sentence does not parse in English, sorry.

Result - Still the same issue the other actions related information is not coming up fine.

If you do not register a receiver for a given broadcast action, you will not receive broadcasts for that action.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号