4. ActivityThread类

ActivityThread 类即代表 Application 主线程。4.1类中关键信息public final classActivityThread {static ContextImpl mSystemContext = null;staticIPackageManager sPackageManager;//创建ApplicationThread实例,以接收AMS指令并执行

final ApplicationThread mAppThread = newApplicationThread();final Looper mLooper =Looper.myLooper();final H mH = newH();final HashMapmActivities= new HashMap();//List of new activities (via ActivityRecord.nextIdle) that should//be reported when next we idle.

ActivityClientRecord mNewActivities = null;//Number of activities that are currently visible on-screen.

int mNumVisibleActivities = 0;final HashMapmServices= new HashMap();

Application mInitialApplication;final ArrayListmAllApplications= new ArrayList();static final ThreadLocal sThreadLocal = new ThreadLocal();

Instrumentation mInstrumentation;static Handler sMainThreadHandler; //set once in main()

static final classActivityClientRecord {

IBinder token;intident;

Intent intent;

Bundle state;

Activity activity;

Window window;

Activity parent;

String embeddedID;

Activity.NonConfigurationInstances lastNonConfigurationInstances;booleanpaused;booleanstopped;booleanhideForNow;

Configuration newConfig;

Configuration createdConfig;

ActivityClientRecord nextIdle;

String profileFile;

ParcelFileDescriptor profileFd;booleanautoStopProfiler;

ActivityInfo activityInfo;

CompatibilityInfo compatInfo;

LoadedApk packageInfo;//包信息,通过调用ActivityThread.getPapckageInfo而获得

ListpendingResults;

ListpendingIntents;booleanstartsNotResumed;booleanisForward;intpendingConfigChanges;booleanonlyLocalRequest;

View mPendingRemoveWindow;

WindowManager mPendingRemoveWindowManager;

...

}private class ApplicationThread extendsApplicationThreadNative {private voidupdatePendingConfiguration(Configuration config) {synchronized(mPackages) {if (mPendingConfiguration == null ||mPendingConfiguration.isOtherSeqNewer(config)) {

mPendingConfiguration=config;

}

}

}public final void schedulePauseActivity(IBinder token, booleanfinished,boolean userLeaving, intconfigChanges) {

queueOrSendMessage(

finished?H.PAUSE_ACTIVITY_FINISHING : H.PAUSE_ACTIVITY,

token,

(userLeaving? 1 : 0),

configChanges);

}//we use token to identify this activity without having to send the//activity itself back to the activity manager. (matters more with ipc)

public final void scheduleLaunchActivity(Intent intent, IBinder token, intident,

ActivityInfo info, Configuration curConfig, CompatibilityInfo compatInfo,

Bundle state, ListpendingResults,

List pendingNewIntents, boolean notResumed, booleanisForward,

String profileName, ParcelFileDescriptor profileFd,booleanautoStopProfiler) {

ActivityClientRecord r= newActivityClientRecord();

r.token=token;

r.ident=ident;

r.intent=intent;

r.activityInfo=info;

r.compatInfo=compatInfo;

r.state=state;

r.pendingResults=pendingResults;

r.pendingIntents=pendingNewIntents;

r.startsNotResumed=notResumed;

r.isForward=isForward;

r.profileFile=profileName;

r.profileFd=profileFd;

r.autoStopProfiler=autoStopProfiler;

updatePendingConfiguration(curConfig);

queueOrSendMessage(H.LAUNCH_ACTIVITY, r);

}

...

}private class H extendsHandler {public voidhandleMessage(Message msg) {if (DEBUG_MESSAGES) Slog.v(TAG, ">>> handling: " +codeToString(msg.what));switch(msg.what) {caseLAUNCH_ACTIVITY: {

Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER,"activityStart");

ActivityClientRecord r=(ActivityClientRecord)msg.obj;

r.packageInfo=getPackageInfoNoCheck(

r.activityInfo.applicationInfo, r.compatInfo);

handleLaunchActivity(r,null);

Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);

}break;

...

}if (DEBUG_MESSAGES) Slog.v(TAG, "<<< done: " +codeToString(msg.what));

}

...

}public staticActivityThread currentActivityThread() {returnsThreadLocal.get();

}public static voidmain(String[] args) {

SamplingProfilerIntegration.start();//CloseGuard defaults to true and can be quite spammy. We//disable it here, but selectively enable it later (via//StrictMode) on debug builds, but using DropBox, not logs.

CloseGuard.setEnabled(false);

Environment.initForCurrentUser();//Set the reporter for event logging in libcore

EventLogger.setReporter(newEventLoggingReporter());

Process.setArgV0("");

Looper.prepareMainLooper();//创建ActivityThread实例

ActivityThread thread = newActivityThread();

thread.attach(false);if (sMainThreadHandler == null) {

sMainThreadHandler=thread.getHandler();

}

AsyncTask.init();if (false) {

Looper.myLooper().setMessageLogging(newLogPrinter(Log.DEBUG,"ActivityThread"));

}

Looper.loop();throw new RuntimeException("Main thread loop unexpectedly exited");

}

}4.2 家族图谱

activitythread.java_ActivityThread相关推荐

  1. 【Android】 01. APP 进程启动和 ActivityThread 的关系

    2019独角兽企业重金招聘Python工程师标准>>> 首先我们应该知道2个概念: 我们应该知道在Android中一个app就是一个进程: 我们在普通的Java程序中一个程序的入口是 ...

  2. Android Hook ActivityThread mH 消息

    背景: 今天面试被问到如何监听ActivityThread mH 类的消息,当时的想法是,mH 其实就是Handler, Android 没有提供获取到mH 的方法,就算我可以拿到mH 的 Loope ...

  3. 【Android 启动过程】Activity 启动源码分析 ( ActivityThread 流程分析 二 )

    文章目录 前言 一.ActivityManagerService.attachApplicationLocked 二.ActivityStackSupervisor.attachApplication ...

  4. 【Android 启动过程】Activity 启动源码分析 ( ActivityThread 流程分析 一 )

    文章目录 一.ActivityThread 主函数启动 二.ActivityThread 绑定 ApplicationThread 三.AMS attachApplication -> atta ...

  5. 【Android 启动过程】Activity 启动源码分析 ( ActivityThread -> Activity、主线程阶段 二 )

    文章目录 前言 一.ActivityThread 类 handleLaunchActivity -> performLaunchActivity 方法 二.Instrumentation.new ...

  6. 【Android 启动过程】Activity 启动源码分析 ( ActivityThread -> Activity、主线程阶段 一 )

    文章目录 前言 一.ClientTransactionHandler.scheduleTransaction 二.ActivityThread.H 处理 EXECUTE_TRANSACTION 消息 ...

  7. 【Android 启动过程】Activity 启动源码分析 ( AMS -> ActivityThread、AMS 线程阶段 二 )

    文章目录 前言 一.热启动与冷启动选择 二.AMS 进程中执行的相关操作 三.通过 Binder 机制转到 ActivityThread 中执行的操作 总结 前言 上一篇博客 [Android 启动过 ...

  8. 【Android 安全】DEX 加密 ( Application 替换 | 分析 Activity 组件中获取的 Application | ActivityThread | LoadedApk )

    文章目录 一. Activity 中的 getApplication() 方法分析 二. ActivityThread 中的 H 处理 消息及 handleLaunchActivity 方法操作 三. ...

  9. 【Android 安全】DEX 加密 ( Application 替换 | ActivityThread 中的 mAllApplications 集合添加 Application )

    文章目录 一. 当前 Application 替换进度 二. ActivityThread 中的 mAllApplications 集合添加 Application 一. 当前 Application ...

最新文章

  1. 2021年普高考成绩查询,山东2021年高考成绩改为6月26日前公布
  2. oracle新建用户名和密码,Oracle安装后忘记用户名或密码+创建新登陆用户
  3. ubuntu安装Java开发环境
  4. ML之FE:特征工程中常用的一些处理手段(缺失值填充、异常值检测等)及其对应的底层代码的实现
  5. html文字自动上翻,jQuery超酷文字随机翻转变换动画特效
  6. 制作WEB在线编辑器-插入HTML标签
  7. 前端解析返回的对象时json显示$ref问题的解决
  8. linux查看每个文件夹占空间大小
  9. 第五篇:路由网关(zuul) zuul路由 服务过滤 (Finchley版本)V2.0_dev
  10. C#利用NOPI处理Excel的代码
  11. 中国人工智能学会通讯——基于视频的行为识别技术 1.5 基于深度学习的视频识别方法...
  12. redis迁移至linux,redis几种数据导出导入方式
  13. Unity3D基础15:触发器
  14. 计算机信息资源管理岗位,信息资源管理专业的可以报考公务员的哪些职位?
  15. 万年历、黄历,获取每日的宜忌、五行、冲煞、值神、彭祖百忌、吉神宜趋、今日胎神、凶神宜忌、二十八星宿、建除十二神
  16. 【NOIP2018提高组D2T2】填数游戏
  17. ADF Faces Core 标记库信息
  18. 白盒测试与黑盒测试--(详解)
  19. 自然语言处理(5)——语言模型
  20. 睁开双眼时,便是那张狰狞阴狠的

热门文章

  1. 数模混合信号建模语言Verilog-AMS
  2. Win10系统安装多个JDK
  3. 解决linux中无法连接网络
  4. 三步开启你的网络服务全球动态加速之旅
  5. i5 10210u和r5 3550h 哪个好
  6. 如何同时给多段视频制作翻转画面的效果
  7. LTD案例|数字化经营方法论在卫浴行业A股上市公司(瑞尔特)的应用
  8. 儿童咳嗽超过四周 小心是哮喘
  9. Java实现 蓝桥杯 算法提高 三角形
  10. mysql建表 联合主键