下載本文檔
版權(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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 人教版初中語文七下《駱駝祥子》基礎復習必刷題(附答案)
- 2026年靈臺縣人民法院招聘備考題庫有答案詳解
- 2026年西安長安大學工程設計研究院有限公司招聘備考題庫含答案詳解
- 2026年欽州市交通運輸局機關及局屬事業(yè)單位編外工作人員和“12328”熱線工作人員招聘8人備考題庫及參考答案詳解一套
- 2025年企業(yè)檔案管理與信息化手冊
- 2025年法律法規(guī)查詢與適用指南
- 2025年大學漢語言文學(現(xiàn)當代文學)試題及答案
- 2026年智慧物流倉儲機器人報告及未來五至十年供應鏈優(yōu)化報告
- 2026年建筑行業(yè):3D打印結(jié)構(gòu)技術(shù)創(chuàng)新與綠色建筑行業(yè)創(chuàng)新報告
- 2025年鄉(xiāng)村文化節(jié)五年活動風險管理報告
- 校外輔導員培訓
- 2025年大學《應急管理-應急管理法律法規(guī)》考試參考題庫及答案解析
- 創(chuàng)意美術(shù)生蠔課件
- 2025年新版考監(jiān)控證的試題及答案
- 2025年上海市事業(yè)單位教師招聘體育學科專業(yè)知識考試
- 小學六年級英語重點語法全總結(jié)
- 基于低軌衛(wèi)星數(shù)據(jù)的熱層大氣密度反演:方法、挑戰(zhàn)與應用
- 2025年國家開放大學《管理學基礎》期末考試備考試題及答案解析
- 黑龍江省安達市職業(yè)能力傾向測驗事業(yè)單位考試綜合管理類A類試題帶答案
- (正式版)DB32∕T 5156-2025 《零碳園區(qū)建設指南》
- 2025年人教版八年級英語上冊各單元詞匯知識點和語法講解與練習(有答案詳解)
評論
0/150
提交評論