Sending and receiving broadcast message in Android
2011-08-06 18:27
561 查看
Sending and receiving broadcast messages enables inter activity communication. Suppose in activity A you have completed a task and you want activity B to react accordingly, then broadcasting helps a lot. A only needs to initialize an intent and send it via
a broadcast message. B needs to set a filter to get the specific messages from A and register a receiver, where the actions upon receving messages are defined.
In activity A, the message can be sent this way
In activity B, the filter and receiver
Easy, right?
a broadcast message. B needs to set a filter to get the specific messages from A and register a receiver, where the actions upon receving messages are defined.
In activity A, the message can be sent this way
Intent broadcastI=new Intent(); broadcastI.setAction("edu.hkust.cse.phoneAdapter.ruleChange"); sendBroadcast(broadcastI);
In activity B, the filter and receiver
IntentFilter filter=new IntentFilter("edu.hkust.cse.phoneAdapter.ruleChange"); this.registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context arg0, Intent arg1) { Toast.makeText(getApplicationContext(), "msg received", Toast.LENGTH_SHORT).show(); } },filter);
Easy, right?
相关文章推荐
- Android Mobile Application - Message casting and receiving
- On blocking the SMS sending and dialing in Android
- Using AlarmManager and BroadcastReceiver in Android
- android wearable-Transferring Assets,Sending and Receiving Messages,Handling Data Layer Events
- Android Broadcast Intents and Broadcast Receivers
- Difference Between Thread and AsyncTask in Android
- Issues in Linux And Android
- android 细节之 AndroidRuntimeException:This message is already in use
- Android Service BroadcastReceiver And File Download
- In android studio,cannot load 2 facets-unknown facet type:android and android-gradle
- Sending files in chunks with MTOM Web Services and .NET 2.0
- Broadcastreceiver components are not allowed to bind to services in android
- Android get layout height and width in a fragment
- Why mobile iOS and Android app should be in Java?
- Creating custom and compound views in Android - Tutorial
- Android 1.5 project in Eclipse and whenever I merely have an x
- Android Bluetooth Data Reception and Sending
- android 接收广播意图错误:java.lang.RuntimeException: Error receiving broadcast Intent { act=android.bluetoot
- Android 子线程发送handle更新UI遇到This message is already in use解决方法