Android Activty的加载过程 启动流程 源码分析
来源:互联网 发布:地方门户源码带手机版 编辑:程序博客网 时间:2024/05/18 15:28
1.Android Binder 作为 IPC 机制原理和面试回答
http://blog.csdn.net/whb20081815/article/details/74436204
2.
Android AIDL进程IPC通信 一次就好
http://blog.csdn.net/whb20081815/article/details/70766913
3.
Android反射(Reflect)完全解析--强势来袭
http://blog.csdn.net/whb20081815/article/details/61198050
4.
Android 2分钟学会xUtils 注解 Annotation(实例+原理)
http://blog.csdn.net/whb20081815/article/details/62423840
5. Android 上下文Context(最权威的官方教程)
http://blog.csdn.net/whb20081815/article/details/70258715
6.Android Activty的加载过程 启动流程 源码分析
http://blog.csdn.net/whb20081815/article/details/76596473
->Instrumentation#execStartActivity()和checkStartActivityResult()(这是在启动了Activity之后判断Activity是否启动成功,例如没有在AM中注册那么就会报错)
->ActivityManagerNative.getDefault().startActivity()(类似AIDL,实现了IAM,实际是由远端的AMS实现startActivity())
->ActivityStackSupervisor#startActivityMayWait()
->ActivityStack#resumeTopActivityInnerLocked
->ActivityStackSupervisor#realStartActivityLocked()(在这里调用APT的scheduleLaunchActivity,也是AIDL,不过是在远端调起了本进程Application线程)
->ApplicationThread#scheduleLaunchActivity()(这是本进程的一个线程,用于作为Service端来接受AMS client端的调起)
->ActivityThread#handleLaunchActivity()(接收内部类H的消息,ApplicationThread线程发送LAUNCH_ACTIVITY消息给H)
->最终在ActivityThread#performLaunchActivity()中实现Activity的启动完成了以下几件事:
最后就是创建和关联window,让Window接收的事件传给Activity,在Window的创建过程中会调用ViewRootImpl的performTraversals()初始化View。
更新界面。
来源: http://www.jianshu.com/p/cf5092fa2694
context启动Activity ,由于
Context
的实现实际上是ContextImpl
;我们看ConetxtImpl
类的startActivity
方法:@Overridepublic void startActivity(Intent intent, Bundle options) { warnIfCallingFromSystemProcess(); // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is // generally not allowed, except if the caller specifies the task id the activity should // be launched in. if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0 && options != null && ActivityOptions.fromBundle(options).getLaunchTaskId() == -1) { throw new AndroidRuntimeException( "Calling startActivity() from outside of an Activity " + " context requires the FLAG_ACTIVITY_NEW_TASK flag." + " Is this really what you want?"); } mMainThread.getInstrumentation().execStartActivity( getOuterContext(), mMainThread.getApplicationThread(), null, (Activity) null, intent, -1, options);}
实际上使用了
ActivityThread
类的mInstrumentation
成员的execStartActivity
方法;注意到,ActivityThread
实际上是主线程正的
startActivity
使用了Instrumentation
类的execStartActivity
方法;继续跟踪:到这里我们发现真正调用的是
ActivityManagerNative
的startActivity
方法public ActivityResult execStartActivity( Context who, IBinder contextThread, IBinder token, Activity target, Intent intent, int requestCode, Bundle options) { IApplicationThread whoThread = (IApplicationThread) contextThread; if (mActivityMonitors != null) { synchronized (mSync) { final int N = mActivityMonitors.size(); for (int i=0; i<N; i++) { final ActivityMonitor am = mActivityMonitors.get(i); if (am.match(who, null, intent)) { am.mHits++; if (am.isBlocking()) { return requestCode >= 0 ? am.getResult() : null; } break; } } } } try { intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(); int result = ActivityManagerNative.getDefault() .startActivity(whoThread, who.getBasePackageName(), intent, intent.resolveTypeIfNeeded(who.getContentResolver()), token, target != null ? target.mEmbeddedID : null, requestCode, 0, null, null, options); checkStartActivityResult(result, intent); } catch (RemoteException e) { } return null;}
- 参考博客:
- http://www.cnblogs.com/carlo/p/4947586.html
http://blog.csdn.net/tenggangren/article/details/50925740
- http://www.jianshu.com/p/eb3afdb9abf3
老罗的博客
http://blog.csdn.net/luoshengyang/article/details/6689748
->Instrumentation#execStartActivity()和checkStartActivityResult()(这是在启动了Activity之后判断Activity是否启动成功,例如没有在AM中注册那么就会报错)
->ActivityManagerNative.getDefault().startActivity()(类似AIDL,实现了IAM,实际是由远端的AMS实现startActivity())
->ActivityStackSupervisor#startActivityMayWait()
->ActivityStack#resumeTopActivityInnerLocked
->ActivityStackSupervisor#realStartActivityLocked()(在这里调用APT的scheduleLaunchActivity,也是AIDL,不过是在远端调起了本进程Application线程)
->ApplicationThread#scheduleLaunchActivity()(这是本进程的一个线程,用于作为Service端来接受AMS client端的调起)
->ActivityThread#handleLaunchActivity()(接收内部类H的消息,ApplicationThread线程发送LAUNCH_ACTIVITY消息给H)
->最终在ActivityThread#performLaunchActivity()中实现Activity的启动完成了以下几件事:
最后就是创建和关联window,让Window接收的事件传给Activity,在Window的创建过程中会调用ViewRootImpl的performTraversals()初始化View。
更新界面。
来源: http://www.jianshu.com/p/cf5092fa2694
context启动Activity ,由于
Context
的实现实际上是ContextImpl
;我们看ConetxtImpl
类的startActivity
方法:@Overridepublic void startActivity(Intent intent, Bundle options) { warnIfCallingFromSystemProcess(); // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is // generally not allowed, except if the caller specifies the task id the activity should // be launched in. if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0 && options != null && ActivityOptions.fromBundle(options).getLaunchTaskId() == -1) { throw new AndroidRuntimeException( "Calling startActivity() from outside of an Activity " + " context requires the FLAG_ACTIVITY_NEW_TASK flag." + " Is this really what you want?"); } mMainThread.getInstrumentation().execStartActivity( getOuterContext(), mMainThread.getApplicationThread(), null, (Activity) null, intent, -1, options);}
实际上使用了
ActivityThread
类的mInstrumentation
成员的execStartActivity
方法;注意到,ActivityThread
实际上是主线程正的
startActivity
使用了Instrumentation
类的execStartActivity
方法;继续跟踪:到这里我们发现真正调用的是
ActivityManagerNative
的startActivity
方法public ActivityResult execStartActivity( Context who, IBinder contextThread, IBinder token, Activity target, Intent intent, int requestCode, Bundle options) { IApplicationThread whoThread = (IApplicationThread) contextThread; if (mActivityMonitors != null) { synchronized (mSync) { final int N = mActivityMonitors.size(); for (int i=0; i<N; i++) { final ActivityMonitor am = mActivityMonitors.get(i); if (am.match(who, null, intent)) { am.mHits++; if (am.isBlocking()) { return requestCode >= 0 ? am.getResult() : null; } break; } } } } try { intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(); int result = ActivityManagerNative.getDefault() .startActivity(whoThread, who.getBasePackageName(), intent, intent.resolveTypeIfNeeded(who.getContentResolver()), token, target != null ? target.mEmbeddedID : null, requestCode, 0, null, null, options); checkStartActivityResult(result, intent); } catch (RemoteException e) { } return null;}
- 参考博客:
- http://www.cnblogs.com/carlo/p/4947586.html
http://blog.csdn.net/tenggangren/article/details/50925740
- http://www.jianshu.com/p/eb3afdb9abf3
老罗的博客
http://blog.csdn.net/luoshengyang/article/details/6689748
阅读全文
0 1
- Android Activty的加载过程 启动流程 源码分析
- Android源码分析-Activity的启动过程
- Android源码分析-Activity的启动过程 .
- Android源码分析-Activity的启动过程
- Android源码分析-Activity的启动过程
- Android源码分析-Activity的启动过程
- Android源码分析-Activity的启动过程
- Android源码分析-Activity的启动过程
- Android源码分析-Activity的启动过程
- android源码分析 Service的启动过程
- Android源码分析-Activity的启动过程
- Android Service启动Activty的方法
- Android 7.0 Launcher3的启动和加载流程分析
- Android 5.0源码分析---Content Provider的启动过程分析
- Android进阶系列之源码分析Activity的启动流程
- Android系统的启动流程分析及如何看源码
- Android Service的启动流程源码分析(8.0)
- Android平台类加载流程源码分析
- 暑假训练第3天总结
- POJ 1681 Painter's Problem (高斯消元)
- Android开发实践:屏幕旋转的处理
- CDH:hdfs劵故障
- CFNetwork internal error (0xc01a:/BuildRoot/Library/Caches/com.apple.xbs/Sources/CFNetwork_Sim/CFNet
- Android Activty的加载过程 启动流程 源码分析
- 设计模式(19)--观察者模式
- LeetCode 3Sum Closest C++
- 2015多校第7场 HDU 5373 The shortest problem 规律,暴力
- LaTeX插入多行多列图
- 学习笔记
- android加入谷歌地图(2)
- 根据@把邮箱的用户名和地址分离,以键值对应的方式放入HashMap中
- C++函数模板