Android Interview Questions and Answers What is android?


Sending A Broadcast Intent To A Specific BroadcastReceiver



Download 0.77 Mb.
View original pdf
Page62/62
Date17.12.2020
Size0.77 Mb.
#54986
1   ...   54   55   56   57   58   59   60   61   62
Android Interview Questions
11. Sending A Broadcast Intent To A Specific BroadcastReceiver
Both normal and ordered broadcast Intents can be sent to a specific BroadcastReceiver by setting the broadcast Intents component explicitly. For example, assuming the Application package is xper.specific and the BroadcastReceiver is declared as follows






then a normal broadcast Intent can be sent to it as follows. sendBroadcast( new Intent
"xper.specific.BROADCAST_INTENT"). setClassName(
"xper.specific",
"xper.specific.SpecificBroadcastReceiver")); Note that, as in this example, the Intent does not have to match the IntentFilter(s) associated with the
BroadcastReceiver, which has some interesting implications. Although specifying the BroadcastReceiver explicitly when sending the broadcast Intent overrides the
BroadcastReceiver’s IntentFilter(s) both sender and/or receiver permissions, if specified, still apply. It is not possible to send a broadcast Intent to a specific BroadcastReceiver in sticky mode. Attempting to do so results in a SecurityException.
12. Anonymous BroadcastReceivers
It is possible to statically register a BroadcastReceiver without any IntentFilters. For example.
Broadcast Intents can still be sent to it by specifying the BroadcastReceiver explicitly
In this can it can only be done from the registering Application since in the BroadcastReceiver has not been exported
It is of course possible to export it as well


Download 0.77 Mb.

Share with your friends:
1   ...   54   55   56   57   58   59   60   61   62




The database is protected by copyright ©ininet.org 2024
send message

    Main page