Android中BroadCast与Activity之间的通信
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Android中BroadCast与Activity之间的通信
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                在看本文之前,假設(shè)你對(duì)于Android的廣播機(jī)制不是非常了解。建議先行閱讀我轉(zhuǎn)載的一篇博文:圖解 Android 廣播機(jī)制。
因?yàn)楸景咐容^簡(jiǎn)單,故直接在此貼出代碼,不做過多的闡述。
先上效果截圖:
MyBroadCast的代碼例如以下:
package com.gc.testbroadcasedemo;import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; /*** * @author Android將軍**/ public class MyBroadCast extends BroadcastReceiver{public MyBroadCast(){Log.v("BROADCAST_TAG", "MyBroadCast");}@Overridepublic void onReceive(Context context, Intent intent) {// TODO Auto-generated method stubLog.v("BROADCAST_TAG", "onReceive");Bundle bundle = intent.getExtras();if(intent.getAction().equals(MainActivity.ACTION_INTENT_TEST)){processCustomMessage(context, bundle);}}//send msg to MainActivityprivate void processCustomMessage(Context context, Bundle bundle) {Intent mIntent=new Intent(MainActivity.ACTION_INTENT_RECEIVER);mIntent.putExtra("message", "測(cè)試Broadcast與Activity之間的通信");context.sendBroadcast(mIntent);}} 案例project文件夾例如以下:
在AndroidManifest中靜態(tài)注冊(cè)MyBroadCast廣播。代碼例如以下:
<receiver android:name=".MyBroadCast"><intent-filter ><action android:name="com.gc.broadcase.test"/></intent-filter></receiver>轉(zhuǎn)載請(qǐng)注明出處:http://blog.csdn.net/android_jiangjun/article/details/39928243
本文轉(zhuǎn)自mfrbuaa博客園博客,原文鏈接:http://www.cnblogs.com/mfrbuaa/p/5261839.html,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者
總結(jié)
以上是生活随笔為你收集整理的Android中BroadCast与Activity之间的通信的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: call,apply,求最大最小值,平均
- 下一篇: Thread.currentThread
