Activity's life cycle is very clear at the android developer website. When try to start an activity, the main function in ActivityThread.java will run first, it will then enter the loop function in Looper.java. Loop function is responsible for the get the message from a message queue and dispatch the message out. Looks like all the message about life cycle will enter to this message queue. The message dispatched from looper will be handled by handleMessage function in ActivityThread.java. All the message about life cycle will be handled here, the message includes activity launch, pause, resume, start, stop, destroy, service bind and others. The below flow chart shows how the message to handle.

How about the life cycle when launch an son activity from a main activity? Below flow chart shows the states of the two activity.

本文详细解析了Android开发者网站上关于应用启动时的生命周期流程。从ActivityThread.java的主函数开始,进入Looper循环处理消息队列中的消息,所有与生命周期相关的消息在这里被处理,包括启动、暂停、恢复、启动服务等。

5608

被折叠的 条评论
为什么被折叠?



