**如下:
1.清單檔案
2.傳送廣播
intent intent =
newintent
("www.wangpeng");
intent.
putextra
("name"
,"我是有序排序");
sendorderedbroadcast
(intent,
null
);
3.接收類
// an highlighted block
string name = intent.
getstringextra
("name");
bundle bundle =
newbundle()
; bundle.
putstring
("xiedai"
,"我是攜帶資料");
setresultextras
(bundle)
; log.d(
"###"
,"我是接受方一:"
+name)
;
// an highlighted block
string name = intent.
getstringextra
("name");
log.d(
"###"
,"我是接受方2:"
+name)
; bundle resultextras =
getresultextras
(true);
string xiedai = resultextras.
getstring
("xiedai");
log.d(
"###"
,"攜帶資料2:"
+xiedai)
;
// an highlighted block
string name = intent.
getstringextra
("name");
bundle resultextras =
getresultextras
(true);
string xiedai = resultextras.
getstring
("xiedai");
log.d(
"###"
,"我是接受方3:"
+name)
; log.d(
"###"
,"攜帶資料3:"
+xiedai)
;
//傳送方
// an highlighted block
public
class
mainactivity
extends
public
void
sendmessage()
public
void
sleepmessage()
catch
(interruptedexception e)}}
).start();}}
//接收方
// an highlighted block
public
class
ontheractivity
extends
class
myrecevier
extends
broadcastreceiver}}
}
1.定義事件
// an highlighted block
public
class
messageevent
public string getmessage()
public
void
setmessage
(string message)
}
有序廣播,粘性廣播
1.註冊多個receiver,要同時使用同乙個action,設定priority來指定優先順序。2.傳送有序廣播 sendorderedbroadcast intent,null intent intent newintent www.wangpeng intent.putextra name 我是...
安卓廣播之理論篇
什麼叫廣播?比如 在 android 裡面有各種各樣的廣播,比如電池的使用狀態,的接收和簡訊的接收都會產生乙個廣播,應用程式開發者也可以監聽這些廣播並做出程式邏輯的處理 android廣播的分類 1 普通廣播 normal broadcasts 依次傳遞給各個處理器去處理 完全非同步的,可以在同一時...
安卓的廣播機制學習
今天學習的是安卓中廣播機制,在周五聽完實驗室陽仔的相關報告之後,我動手做了一些小練習,並且在過程中遇到了一些問題。1.在實現button的監聽是,我匯入的onclicklistener的包有誤,並不是android.view.view.onclicklitener 2.靜態註冊接收器時,使用了內部類...