下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】Android浏览器的研究(四)Apk的启动和主页的加载过程
当我们在Launcher中点击浏览器的图标时,浏览器的窗口会打开并显示主页(HomePage)。这里我们对这一场景进行分析,研究浏览器如何启动,取得缺省主页并将它布局和显示的。根据前边对WebView类的学习,大概可以预期我们在主Activity的onCreate方法里从设置里面取得缺省主页的配置,创建一个WebView类,并使用setContentView将它添加到主窗口中。下面我们从浏览器的代码看看它是如何实现的。首先,研究AndroidManifest文件,从<application>标签的内容看到该Apk实现了自己的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的创建,PhoneUi的创建和Controller的start。Controller的构造方法主要涉及到以下几个相关类:BrowserSettingsTabControlCrashRecoveryHandlerUrlHandlerBrowserWebViewFactoryIntentHandlerPageDialogHandlerBookMarks的ContentObserverNetworkStateHandlerSystemAllowGeolocationOriginsIconDataBasePhoneUi的构造:
BaseUi的构造: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>可以看出这个是浏览器主界面的布局,浏览器的布局已经准备好,后面我们创建的WebView应该是添加到main_content里面。Controller的start方法执行了CrashRecoveryHandler的startRecovery().CrashRecoveryHandler相关操作:首先是initialize(),创建了CrashRecoveryHandler实例,CrashRecoveryHandler实例构造了foregroundHandler和backgroundHandler。CrashRecoveryHandler的preloadCrashState方法,在backgroundHandler的处理中执行loadCrashState(),该方法将CrashState从STATE_FILE读入到mRecoveryState中。CrashRecoveryHandler的startRecovery方法,调用Controller的doStart()。Controller的doStart方法调用onPreloginFinished().currentTabIdis-1,thenopenTabToHomePage().openTabToHomePagecreateNewTabthenloadUrl.createNewTab的实现:TabControl::createNewTabcreateNewWebView:newBrowserWebView;该类主要用来管理WebView滚动条事件。initWebViewSettings;setActiveTabTabControl::setCurrentTabPhoneUi::setActiveTabattachTabToContentView至此,我们看完Apk启动并加载HomePage的过程,简单总结如下:1.浏览器实现了自己的Application类(Browser),在其onCreate方法中进行了一些初始化工作(Cookie同步管理,浏览器设置和预加载);2.浏览器的主Activity是BrowserActivity,在其onCreate方法中构建了Controller和PhoneUi,并调用Controller::start方法启动Controller;a)Controller在其构造方法中实例化和初始化一些协助对象,其中一个重要的类是CrashRecoveryHandler;b)Ph
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 公共设施管理与维护操作手册(标准版)
- 车站人员考勤管理制度
- 财务管理制度
- 办公室员工培训课程更新制度
- 办公室出差与报销管理制度
- 2026年锡山城发集团公开招聘5人备考题库及完整答案详解1套
- 人教版初中语文七下《骆驼祥子》基础复习必刷题(附答案)
- 2026年葫芦岛市南票区政府专职消防队员招聘37人备考题库及参考答案详解一套
- 关于选聘“警民联调”室专职人民调解员20人的备考题库参考答案详解
- 2026年灵台县人民法院招聘备考题库有答案详解
- 校外辅导员培训
- 2025年大学《应急管理-应急管理法律法规》考试参考题库及答案解析
- 创意美术生蚝课件
- 2025年新版考监控证的试题及答案
- 2025年上海市事业单位教师招聘体育学科专业知识考试
- 小学六年级英语重点语法全总结
- 基于低轨卫星数据的热层大气密度反演:方法、挑战与应用
- 2025年国家开放大学《管理学基础》期末考试备考试题及答案解析
- 黑龙江省安达市职业能力倾向测验事业单位考试综合管理类A类试题带答案
- (正式版)DB32∕T 5156-2025 《零碳园区建设指南》
- 2025年人教版八年级英语上册各单元词汇知识点和语法讲解与练习(有答案详解)
评论
0/150
提交评论