framework(一):ActivityThread-笔记

来源:互联网 发布:专业看盘软件 编辑:程序博客网 时间:2024/06/06 04:17

ActivityThread 的功能是管理应用程序进程中的主线程,包括调度和执行Activity,broadcasts以及其它的请求操作。

当用户打开一个应用程序时,会由AMS(ActivityMangerService)创建一个ActivityThread,当然ActivityThread并不是一个线程类,但是其所在的线程就是主线程,也就是常说的UI 线程。

public static void main(String[] args) {5185        SamplingProfilerIntegration.start();51865187        // CloseGuard defaults to true and can be quite spammy.  We5188        // disable it here, but selectively enable it later (via5189        // StrictMode) on debug builds, but using DropBox, not logs.5190        CloseGuard.setEnabled(false);51915192        Environment.initForCurrentUser();51935194        // Set the reporter for event logging in libcore5195        EventLogger.setReporter(new EventLoggingReporter());51965197        Security.addProvider(new AndroidKeyStoreProvider());51985199        // Make sure TrustedCertificateStore looks in the right place for CA certificates5200        final File configDir = Environment.getUserConfigDirectory(UserHandle.myUserId());5201        TrustedCertificateStore.setDefaultUserDirectory(configDir);52025203        Process.setArgV0("<pre-initialized>");52045205        Looper.prepareMainLooper();52065207        ActivityThread thread = new ActivityThread();5208        thread.attach(false);52095210        if (sMainThreadHandler == null) {5211            sMainThreadHandler = thread.getHandler();5212        }52135214        AsyncTask.init();52155216        if (false) {5217            Looper.myLooper().setMessageLogging(new5218                    LogPrinter(Log.DEBUG, "ActivityThread"));5219        }52205221        Looper.loop();52225223        throw new RuntimeException("Main thread loop unexpectedly exited");5224    }5225}
由main方法进入消息循环。


0 0