資源描述:
《將定制的Launcher設(shè)置為默認(rèn).doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、Android如何將定制的Launcher成為系統(tǒng)中唯一的Launcher2011-01-1711:12如果你要定制一個(gè)Android系統(tǒng),你想用你自己的Launcher(Home)作主界面來替換Android自己的Home,而且不希望用戶安裝的Launcher來替換掉你的Launcher.我們可以通過修改Framework來實(shí)現(xiàn)這樣的功能。這里以Android2.1的源代碼為例來實(shí)際說明。1)首先了解一下Android的啟動(dòng)過程。??Android系統(tǒng)的啟動(dòng)先從Zygote開始啟動(dòng),然后……(中間的過程就不
2、說了)…..一直到了SystemServer(framework)這個(gè)地方,看到這段代碼:????/**????*ThismethodiscalledfromZygotetoinitializethesystem.Thiswillcausethenative????*services(SurfaceFlinger,AudioFlinger,etc..)tobestarted.Afterthatitwillcallback????*upintoinit2()tostarttheAndroidservices.?
3、???*/??nativepublicstaticvoidinit1(String[]args);??publicstaticvoidmain(String[]args){??????if(SamplingProfilerIntegration.isEnabled()){????????SamplingProfilerIntegration.start();????????timer=newTimer();????????timer.schedule(newTimerTask(){??????????@Ove
4、rride??????????publicvoidrun(){??????????????SamplingProfilerIntegration.writeSnapshot(“system_server”);??????????}????????},SNAPSHOT_INTERVAL,SNAPSHOT_INTERVAL);??????}??????//Thesystemserverhastorunallofthetime,soitneedstobe??????//asefficientaspossiblewi
5、thitsmemoryusage.??????VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);??????System.loadLibrary(“android_servers”);??????init1(args);??}??publicstaticfinalvoidinit2(){??????Log.i(TAG,“EnteredtheAndroidsystemserver!”);??????Threadthr=newServerThread();
6、??????thr.setName(“android.server.ServerThread”);??????thr.start();??}}從SystemServer的main函數(shù)開始啟動(dòng)各種服務(wù)。首先啟動(dòng)init1,然后啟動(dòng)init2.從上面的注釋可以看到:init1這個(gè)方法時(shí)被Zygote調(diào)用來初始化系統(tǒng)的,init1會(huì)啟動(dòng)native的服務(wù)如SurfaceFlinger,AudioFlinger等等,這些工作做完以后會(huì)回調(diào)init2來啟動(dòng)Android的service。這里我們主要來關(guān)注init2的過
7、程。init2中啟動(dòng)ServerThread線程,ServerThread中啟動(dòng)了一系列的服務(wù),比如這些:ActivityManagerServiceEntropyServicePowerManagerServiceTelephonyRegistryPackageManagerServiceAccountManagerServiceBatteryServiceHardwareServiceWatchdogSensorServiceBluetoothServiceStatusBarServiceClipboar
8、dServiceInputMethodManagerServiceNetStatServiceConnectivityServiceAccessibilityManagerServiceNotificationManagerServiceMountServiceDeviceStorageMonitorServiceLocationManagerServiceSearchManagerServiceF