android系统启动流程

系统启动

  1. 打开电源 引导芯片代码加载引导程序Boot Loader到RAM中去执行
  2. BootLoader把操作系统拉起来
  3. Linux 内核启动开始系统设置,找到一个init.rc文件启动初始化进程
  4. init进程初始化和启动属性服务,之后开启Zygote进程
  5. Zygote开始创建JVM并注册JNI方法,开启SystemServer
  6. 启动Binder线程池和SystemServiceManager,并启动各种服务
  7. AMS启动Launcher

Launcher(Application)启动

Launcher启动流程

  1. 当我们点击一个图标时,就到了这个类public final class Launcher extends Activity
    执行onClick(View view)方法,会把这个应用的相关信息传入
    先获取一个intent—>startActivitySafely(v, intent, tag)–》startActivity(v, intent, tag);–>startActivity(intent);
  2. startActivity(intent)会开一个APP进程
  3. ActivityThread.java做为入口 用attach开启app 再加载application和activity
    thread.attach(false);—》mgr.attachApplication(mAppThread)会通过远端进程去
    回调private void handleBindApplication(AppBindData data)
    Application app = data.info.makeApplication(创建Application对象
    mInstrumentation.callApplicationOnCreate(app);----》 app.onCreate();

黑白屏问题

  1. 单独做成一个主题
<style name="AppTheme.Launcher">
        <item name="android:windowBackground">@drawable/bg</item>
    </style>
    <style name="AppTheme.Launcher1">
        <item name="android:windowBackground">@drawable/bg</item>
    </style>
    <style name="AppTheme.Launcher2">
        <item name="android:windowBackground">@drawable/bg</item>
    </style>

  1. 清单中的单独activity下设置
<activity
            android:theme="@style/AppTheme.Launcher"

程序中使用setTheme(R.style.AppTheme);
让APP中所有的activity还是使用以前的样式,只有启动时才使用自己的样式

  1. QQ中的用法
 <item name="android:windowDisablePreview">true</item>
    <item name="android:windowBackground">@null</item>

Trace工具分析代码执行时间

开启Trace并设置文件路径

时间范围

File file = new File(Environment.getExternalStorageDirectory(), "app1.trace");
Debug.startMethodTracing(filePath);
     中间为需要统计执行时间的代码
Debug.stopMethodTracing();

路径

trace文件查看

运行启动APP,会在指定路径下生成一个.trace的文件(注意开启存储权限),将此文件拖入AndroidStudio中
时间查看
执行时间

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:22 天前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐