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

正文內(nèi)容

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

2025-09-19 16:01本頁面

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

  

【正文】 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對象 → 根據(jù) ID找到相應(yīng)控件 → 根據(jù) ID找到相應(yīng)控件 → 根據(jù) ID找到相應(yīng)控件 → 創(chuàng)建一個 Intent對象 → 設(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對象 → 將代理類轉(zhuǎn)換成 IBinder對象 → 銷毀時解綁 Service → 解綁 Service 調(diào)用系統(tǒng)服務(wù) 在 Android系統(tǒng)中提供了很多內(nèi)置服務(wù)類,通過它們提供的系列方法,可以獲取系統(tǒng)相關(guān)信息。 發(fā)送短信需要調(diào)用系統(tǒng)的短信服務(wù),主要用到 SmsManager管理類,該類可以實現(xiàn)短信的管理功能,通過 sendXxxMessage()方法進(jìn)行短信的發(fā)送操作,例如 sendTextMessage()方法用于發(fā)送文本信息 PendingIntent是對 Intent的包裝,一般通過調(diào)用Pendingintent的 getActivity()、 getService() 等靜態(tài)方法來獲取 PendingIntent對象。與 Intent對象不同的是:PendingIntent通常會傳給其他應(yīng)用組件,從而由其他應(yīng)用程序來執(zhí)行 PendingIntent所包裝的“ Intent” 。 調(diào)用系統(tǒng)服務(wù)案例 以下程序提供兩個文本框,分別輸入收信人的號碼和發(fā)送的短信內(nèi)容,通過點擊“發(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ù)案例 以下程序提供兩個文本框,分別輸入收信人的號碼和發(fā)送的短信內(nèi)容,通過點擊“發(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ù)案例 以下程序提供兩個文本框,分別輸入收信人的號碼和發(fā)送的短信內(nèi)容,通過點擊“發(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ù)案例 以下程序提供兩個文本框,分別輸入收信人的號碼和發(fā)送的短信內(nèi)容,通過點擊“發(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()。 } })。 } }
點擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1