概述
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的全部内容,希望文章能够帮你解决activitythread.java_ActivityThread所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复