freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

第5章android服務(wù)service-資料下載頁(yè)

2024-09-28 16:01本頁(yè)面

【導(dǎo)讀】Service是android系統(tǒng)中的一種組件,它跟Activity的級(jí)別差不多,它們都是從Context派生出來(lái)的,但是它不能自己運(yùn)行,只能在后臺(tái)運(yùn)行,并且可以和其它組件進(jìn)行交互。在Android系統(tǒng)中,常采用以下兩種方式啟動(dòng)Service.通過(guò)Context的startService()啟動(dòng)service后,訪問(wèn)者與service之間沒(méi)有關(guān)。這種情況下,service與訪問(wèn)者之間無(wú)法進(jìn)行通信,數(shù)據(jù)交換,往。往用于執(zhí)行單一操作,并且沒(méi)有返回結(jié)果。例如通過(guò)網(wǎng)絡(luò)上傳,下載文件,操作。一旦完成,服務(wù)應(yīng)該自動(dòng)銷毀。通過(guò)Context的bindService()綁定Service,綁定后Service就和調(diào)用。者阻塞的操作,你應(yīng)該在服務(wù)中創(chuàng)建一個(gè)新的線程去處理。通過(guò)使用獨(dú)立的線程,你就會(huì)。可以保持與用戶的交互。所有Service子類必須實(shí)現(xiàn)該方法。voidonDestroy():當(dāng)Service被關(guān)閉之前,將回調(diào)該方法;booleanonUnbind:當(dāng)該Service上綁定的所有客戶。端都斷開(kāi)連接時(shí)將會(huì)回調(diào)該方法。開(kāi)發(fā)Service組件需要先開(kāi)發(fā)一個(gè)Service子類,然后在。/>元素指定它可被哪些Intent啟動(dòng)。

  

【正文】 Client/src/iet/jxufe//android/client/ public class MainActivity extends Activity { private Button getData。 private EditText name,author。 private Song songBinder。 public void onCreate(Bundle savedInstanceState) { (savedInstanceState)。 setContentView()。 getData=(Button)findViewById()。 name=(EditText)findViewById()。 author=(EditText)findViewById()。 final Intent intent=new Intent()。 ()。 bindService(intent, conn, )。 (new OnClickListener() { public void onClick(View v) { try{ (())。 (())。 } → 用于獲取其他進(jìn)程數(shù)據(jù)的按鈕 → 顯示獲取的數(shù)據(jù)的文本編輯框 → 用戶交互的 IBinder對(duì)象 → 根據(jù) ID找到相應(yīng)控件 → 根據(jù) ID找到相應(yīng)控件 → 根據(jù) ID找到相應(yīng)控件 → 創(chuàng)建一個(gè) Intent對(duì)象 → 設(shè)置 Intent的特征 → 綁定 Service → 添加單擊事件處理 → 顯示獲取的數(shù)據(jù) 建立 AIDL客戶端 案例 catch(Exception ex){ ()。 } } })。 } private ServiceConnection conn=new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { songBinder=null。 } public void onServiceConnected(ComponentName name, IBinder service) { songBinder=(service)。 } }。 protected void onDestroy() { ()。 unbindService(conn)。 }。 → 創(chuàng)建 ServiceConnection對(duì)象 → 將代理類轉(zhuǎn)換成 IBinder對(duì)象 → 銷毀時(shí)解綁 Service → 解綁 Service 調(diào)用系統(tǒng)服務(wù) 在 Android系統(tǒng)中提供了很多內(nèi)置服務(wù)類,通過(guò)它們提供的系列方法,可以獲取系統(tǒng)相關(guān)信息。 發(fā)送短信需要調(diào)用系統(tǒng)的短信服務(wù),主要用到 SmsManager管理類,該類可以實(shí)現(xiàn)短信的管理功能,通過(guò) sendXxxMessage()方法進(jìn)行短信的發(fā)送操作,例如 sendTextMessage()方法用于發(fā)送文本信息 PendingIntent是對(duì) Intent的包裝,一般通過(guò)調(diào)用Pendingintent的 getActivity()、 getService() 等靜態(tài)方法來(lái)獲取 PendingIntent對(duì)象。與 Intent對(duì)象不同的是:PendingIntent通常會(huì)傳給其他應(yīng)用組件,從而由其他應(yīng)用程序來(lái)執(zhí)行 PendingIntent所包裝的“ Intent” 。 調(diào)用系統(tǒng)服務(wù)案例 以下程序提供兩個(gè)文本框,分別輸入收信人的號(hào)碼和發(fā)送的短信內(nèi)容,通過(guò)點(diǎn)擊“發(fā)送短信”按鈕即可將短信發(fā)送出去。 程序清單: /SendMessage/res/layout/ LinearLayout xmlns:android= xmlns:tools= android:layout_width=match_parent android:layout_height=match_parent android:paddingLeft=20dp android:orientation=vertical TextView android:layout_width=fill_parent android:layout_height=wrap_content android:textSize=18sp android:text=@string/num/ EditText android:layout_width=fill_parent android:layout_height=wrap_content android:id=@+id/num android:inputType=number/ 調(diào)用系統(tǒng)服務(wù)案例 以下程序提供兩個(gè)文本框,分別輸入收信人的號(hào)碼和發(fā)送的短信內(nèi)容,通過(guò)點(diǎn)擊“發(fā)送短信”按鈕即可將短信發(fā)送出去。 程序清單: /SendMessage/res/layout/ TextView android:layout_width=fill_parent android:layout_height=wrap_content android:textSize=18sp android:text=@string/content/ EditText android:layout_width=fill_parent android:layout_height=wrap_content android:id=@+id/Mess android:minLines=3/ Button android:layout_height=wrap_content android:layout_width=wrap_content android:id=@+id/btn android:text=@string/btn/ /LinearLayout 調(diào)用系統(tǒng)服務(wù)案例 以下程序提供兩個(gè)文本框,分別輸入收信人的號(hào)碼和發(fā)送的短信內(nèi)容,通過(guò)點(diǎn)擊“發(fā)送短信”按鈕即可將短信發(fā)送出去。 程序清單: /SendMessage/res/layout/ public class MainActivity extends Activity { EditText num, mess。 Button btn。 public void onCreate(Bundle savedInstanceState) { (savedInstanceState)。 setContentView()。 btn = (Button) findViewById()。 num = (EditText) findViewById()。 mess = (EditText) findViewById()。 (new OnClickListener() { public void onClick(View v) { String mobile=().toString()。 String content=().toString()。 SmsManager smsManager = ()。 調(diào)用系統(tǒng)服務(wù)案例 以下程序提供兩個(gè)文本框,分別輸入收信人的號(hào)碼和發(fā)送的短信內(nèi)容,通過(guò)點(diǎn)擊“發(fā)送短信”按鈕即可將短信發(fā)送出去。 程序清單: /SendMessage/res/layout/ PendingIntent sentIntent = ( , 0, new Intent(), 0)。 ListString msgs = (content)。 for (String msg : msgs) { (mobile, null, msg sentIntent,null)。 } (, 短信發(fā)送完成! , ).show()。 } })。 } }
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1