最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android的Service應(yīng)用程序組件基本編寫方法

 更新時(shí)間:2012年12月10日 15:55:24   作者:  
Service是一個(gè)android 系統(tǒng)中的應(yīng)用程序組件,它跟Activity的級(jí)別差不多,但是他沒(méi)有圖形化界面,不能自己運(yùn)行,只能后臺(tái)運(yùn)行,Service通常用來(lái)處理一些耗時(shí)比較長(zhǎng)的操作
Service是什么
Service是一個(gè)android 系統(tǒng)中的應(yīng)用程序組件,它跟Activity的級(jí)別差不多,但是他沒(méi)有圖形化界面,不能自己運(yùn)行,只能后臺(tái)運(yùn)行,并且可以和其他組件進(jìn)行交互如更新ContentProvider,Intent以及系統(tǒng)的通知等等。其啟動(dòng)方式有兩種:context.startService() 和 context.bindService()。Service通常用來(lái)處理一些耗時(shí)比較長(zhǎng)的操作。

Service的編寫
創(chuàng)建一個(gè)類(這里為FirstService)繼承android.app.Service,并覆蓋以下方法:
onBind(Intent intent) Return the communication channel to the service.
onCreate() Called by the system when the service is first created.
onStartCommand(Intent intent, int flags, int startId) Called by the system every time a client explicitly starts the service by calling startService(Intent), providing the arguments it supplied and a unique integer token representing the start request.
onDestroy() Called by the system to notify a Service that it is no longer used and is being removed.

AndroidManifest.xml文件中添加service配置
復(fù)制代碼 代碼如下:

<service android:name=".FirstService"></service>

在Activity中啟動(dòng)和停止Service的點(diǎn)擊事件的編寫
復(fù)制代碼 代碼如下:

class StartServiceListener implements OnClickListener {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(TestActivity.this, FirstService.class);
startService(intent);
}
}
class StopServiceListener implements OnClickListener {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(TestActivity.this, FirstService.class);
stopService(intent);
}
}

相關(guān)文章

最新評(píng)論

宁波市| 汤阴县| 砚山县| 永宁县| 兴安县| 噶尔县| 武安市| 旅游| 宁安市| 营口市| 山阴县| 奉化市| 塔河县| 微博| 九龙城区| 肥西县| 淮安市| 巴林左旗| 精河县| 长白| 阳西县| 茌平县| 南昌县| 营口市| 习水县| 徐汇区| 若尔盖县| 梁平县| 盱眙县| 丁青县| 江华| 神农架林区| 上栗县| 楚雄市| 桐柏县| 紫阳县| 泰来县| 雅安市| 怀仁县| 山东省| 通渭县|