应用程序的入口
当启动应用程序时会由ActivityMangerService孵化一个进程,并且实例化一个ActivityThread对象,该类为fianl类型,并不是一个线程类,该类mian()方法实现了常说的消息循环
public static void main(String[] args) {
5185
SamplingProfilerIntegration.start();
5186
5187
// CloseGuard defaults to true and can be quite spammy. We
5188
// disable it here, but selectively enable it later (via
5189
// StrictMode) on debug builds, but using DropBox, not logs.
5190
CloseGuard.setEnabled(false);
5191
5192
Environment.initForCurrentUser();
5193
5194
// Set the reporter for event logging in libcore
5195
EventLogger.setReporter(new EventLoggingReporter());
5196
5197
Security.addProvider(new AndroidKeyStoreProvider());
5198
5199
// Make sure TrustedCertificateStore looks in the right place for CA certificates
5200
final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId());
5201
TrustedCertificateStore.setDefaultUserDirectory(configDir);
5202
5203
Process.setArgV0("<pre-initialized>");
5204
5205
Looper.prepareMainLooper();
5206
5207
ActivityThread thread = new ActivityThread();
5208
thread.attach(false);
5209
5210
if (sMainThreadHandler == null) {
5211
sMainThreadHandler = thread.getHandler();
5212
}
5213
5214
AsyncTask.init();
5215
5216
if (false) {
5217
Looper.myLooper().setMessageLogging(new
5218
LogPrinter(Log.DEBUG, "ActivityThread"));
5219
}
5220
5221
Looper.loop();
5222
5223
throw new RuntimeException("Main thread loop unexpectedly exited");
5224
}
5225
}
该类中还有一个内部类ApplicationThread该类可以说是ActivityMangerService和应用程序通信的桥梁,private class ApplicationThread extends ApplicationThreadNative 该类是一个Binder类型结构的,用于通信,可以说是操作应用程序的命令的发送者。