【移動應用開發(fā)技術(shù)】Android 瀏覽器的研究(四)- Apk的啟動和主頁的加載過程_第1頁
【移動應用開發(fā)技術(shù)】Android 瀏覽器的研究(四)- Apk的啟動和主頁的加載過程_第2頁
【移動應用開發(fā)技術(shù)】Android 瀏覽器的研究(四)- Apk的啟動和主頁的加載過程_第3頁
【移動應用開發(fā)技術(shù)】Android 瀏覽器的研究(四)- Apk的啟動和主頁的加載過程_第4頁
【移動應用開發(fā)技術(shù)】Android 瀏覽器的研究(四)- Apk的啟動和主頁的加載過程_第5頁
免費預覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領

文檔簡介

【移動應用開發(fā)技術(shù)】Android瀏覽器的研究(四)Apk的啟動和主頁的加載過程

當我們在Launcher中點擊瀏覽器的圖標時,瀏覽器的窗口會打開并顯示主頁(HomePage)。這里我們對這一場景進行分析,研究瀏覽器如何啟動,取得缺省主頁并將它布局和顯示的。根據(jù)前邊對WebView類的學習,大概可以預期我們在主Activity的onCreate方法里從設置里面取得缺省主頁的配置,創(chuàng)建一個WebView類,并使用setContentView將它添加到主窗口中。下面我們從瀏覽器的代碼看看它是如何實現(xiàn)的。首先,研究AndroidManifest文件,從<application>標簽的內(nèi)容看到該Apk實現(xiàn)了自己的Applicaton類Browser:<applicationandroid:name="Browser"

android:label="@string/application_name"

android:icon="@mipmap/ic_launcher_browser"

android:backupAgent=".BrowserBackupAgent"

android:hardwareAccelerated="true"

android:taskAffinity="android.task.browser"><activityandroid:name="BrowserActivity"

android:label="@string/application_name"

android:launchMode="singleTask"

android:alwaysRetainTaskState="true"

android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"

android:theme="@style/BrowserTheme"

android:windowSoftInputMode="adjustResize">。。。<!--Wearealsothemainentrypointofthebrowser.-->

<intent-filter>

<actionandroid:name="ent.action.MAIN"/>

<categoryandroid:name="ent.category.DEFAULT"/>

<categoryandroid:name="ent.category.LAUNCHER"/>

<categoryandroid:name="ent.category.BROWSABLE"/>

<categoryandroid:name="ent.category.APP_BROWSER"/>

</intent-filter>Apk的啟動,首先是ApplicationBrowser類的onCreate方法,主要工作:

//createCookieSyncManagerwithcurrentContext

CookieSyncManager.createInstance(this);

BrowserSettings.initialize(getApplicationContext());

Preloader.initialize(getApplicationContext());這里涉及到三個工作:Cookie同步管理,瀏覽器設置和預加載。然后是Activity的onCreate方法,與我們的研究相關的代碼:@Override

publicvoidonCreate(Bundleicicle){

if(LOGV_ENABLED){

Log.v(LOGTAG,this+"onStart,hasstate:"

+(icicle==null?"false":"true"));

}

super.onCreate(icicle);

mController=createController();

Intentintent=(icicle==null)?getIntent():null;

mController.start(intent);

}privateControllercreateController(){

Controllercontroller=newController(this);

booleanxlarge=isTablet(this);

UIui=null;

if(xlarge){

ui=newXLargeUi(this,controller);

}else{

ui=newPhoneUi(this,controller);

}

controller.setUi(ui);

returncontroller;

}主要的工作是Controller的創(chuàng)建,PhoneUi的創(chuàng)建和Controller的start。Controller的構(gòu)造方法主要涉及到以下幾個相關類:BrowserSettingsTabControlCrashRecoveryHandlerUrlHandlerBrowserWebViewFactoryIntentHandlerPageDialogHandlerBookMarks的ContentObserverNetworkStateHandlerSystemAllowGeolocationOriginsIconDataBasePhoneUi的構(gòu)造:

BaseUi的構(gòu)造:FrameLayoutframeLayout=(FrameLayout)mActivity.getWindow()

.getDecorView().findViewById(android.R.id.content);

LayoutInflater.from(mActivity)

.inflate(R.layout.custom_screen,frameLayout);

mFixedTitlebarContainer=(FrameLayout)frameLayout.findViewById(

R.id.fixed_titlebar_container);

mContentView=(FrameLayout)frameLayout.findViewById(

R.id.main_content);

mCustomViewContainer=(FrameLayout)frameLayout.findViewById(

R.id.fullscreen_custom_content);

mErrorConsoleContainer=(LinearLayout)frameLayout

.findViewById(R.id.error_console);Custom_screen的layout文件:<merge

xmlns:android="/apk/res/android">

<FrameLayoutandroid:id="@+id/fullscreen_custom_content"

android:visibility="gone"

android:background="@color/black"

android:layout_width="match_parent"

android:layout_height="match_parent"

/>

<com.android.browser.view.CustomScreenLinearLayout

android:orientation="vertical"

android:id="@+id/vertical_layout"

android:layout_width="match_parent"

android:layout_height="match_parent">

<LinearLayoutandroid:id="@+id/error_console"

android:layout_width="match_parent"

android:layout_height="wrap_content"

/>

<FrameLayoutandroid:id="@+id/fixed_titlebar_container"

android:layout_width="match_parent"

android:layout_height="wrap_content"

/>

<FrameLayoutandroid:id="@+id/main_content"

android:layout_width="match_parent"

android:layout_height="match_parent"

/>

</com.android.browser.view.CustomScreenLinearLayout>

</merge>可以看出這個是瀏覽器主界面的布局,瀏覽器的布局已經(jīng)準備好,后面我們創(chuàng)建的WebView應該是添加到main_content里面。Controller的start方法執(zhí)行了CrashRecoveryHandler的startRecovery().CrashRecoveryHandler相關操作:首先是initialize(),創(chuàng)建了CrashRecoveryHandler實例,CrashRecoveryHandler實例構(gòu)造了foregroundHandler和backgroundHandler。CrashRecoveryHandler的preloadCrashState方法,在backgroundHandler的處理中執(zhí)行l(wèi)oadCrashState(),該方法將CrashState從STATE_FILE讀入到mRecoveryState中。CrashRecoveryHandler的startRecovery方法,調(diào)用Controller的doStart()。Controller的doStart方法調(diào)用onPreloginFinished().currentTabIdis-1,thenopenTabToHomePage().openTabToHomePagecreateNewTabthenloadUrl.createNewTab的實現(xiàn):TabControl::createNewTabcreateNewWebView:newBrowserWebView;該類主要用來管理WebView滾動條事件。initWebViewSettings;setActiveTabTabControl::setCurrentTabPhoneUi::setActiveTabattachTabToContentView至此,我們看完Apk啟動并加載HomePage的過程,簡單總結(jié)如下:1.瀏覽器實現(xiàn)了自己的Application類(Browser),在其onCreate方法中進行了一些初始化工作(Cookie同步管理,瀏覽器設置和預加載);2.瀏覽器的主Activity是BrowserActivity,在其onCreate方法中構(gòu)建了Controller和PhoneUi,并調(diào)用Controller::start方法啟動Controller;a)Controller在其構(gòu)造方法中實例化和初始化一些協(xié)助對象,其中一個重要的類是CrashRecoveryHandler;b)Ph

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論