Android Interview Questions and Answers What is android?


Sending A Sticky Ordered Broadcast Intent



Download 0.77 Mb.
View original pdf
Page57/62
Date17.12.2020
Size0.77 Mb.
#54986
1   ...   54   55   56   57   58   59   60   61   62
Android Interview Questions
9.2 Sending A Sticky Ordered Broadcast Intent
An ordered broadcast Intent can be sent in sticky mode using an implementation of the android.content.Context public abstract void sendStickyOrderedBroadcast(
Intent intent,
BroadcastReceiver resultReceiver,
Handler scheduler, int initialCode,
String initialData,
Bundle initialExtras) method. This works in the same way as the long-form method for sending an ordered broadcast Intent.
9.3 Sticky Broadcast Intent Replacement
If when a broadcast Intent is sent in sticky mode it is found to match a sticky broadcast Intent sent previously then it will replace the existing one. The
Intent.filterEquals()
method is used to determine whether Intents match. One implication of this is that there can be multiple sticky broadcast Intents with, for example, the same action but different data URIs
, since these will not match. Conversely, broadcast Intents that differ only in their extras will match. Note also that an ordered broadcast Intent sent in sticky mode can replace a normal broadcast Intent sent in sticky mode, and vice-versa. For example, the following
IntentFilter f = new IntentFilter("xper.sticky.BROADCAST_INTENT"); sendStickyBroadcast( new Intent


"xper.sticky.BROADCAST_INTENT"). putExtra(
"Type,
"Normal
System.out.println(registerReceiver(null, f).getStringExtra("Type")); sendStickyOrderedBroadcast( new Intent
"xper.sticky.BROADCAST_INTENT"). putExtra(
"Type,
"Ordered, null, null,
0, null, null
System.out.println(registerReceiver(null, f).getStringExtra("Type")); sendStickyBroadcast( new Intent
"xper.sticky.BROADCAST_INTENT"). putExtra(
"Type,
"Normal
System.out.println(registerReceiver(null, f).getStringExtra("Type")); will print
Normal
Ordered
Normal

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