activitythread.java_ActivityThread

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 家族图谱

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值