管理活动的生命周期
依赖和先决条件
如何创建一个Android项目(参见创建一个Android项目)
你也应该阅读
试一试
ActivityLifecycle.zip
As a user navigates through, out of, and back to your app, the Activity
instances in your app transition between different states in their lifecycle.
For instance, when your activity starts for the first time, it comes to the foreground of the system and receives user focus. During this process, the Android system calls a series of lifecycle methods on the activity in which you set up the user interface
and other components. If the user performs an action that starts another activity or switches to another app, the system calls another set of lifecycle methods on your activity as it moves into the background (where the activity is no longer visible, but
the instance and its state remains intact).
用户通过导航,跳出,返回到您的应用程序,是您应用程序中Activity
实例的生命周期在不同状态之间的过渡。举个例子来说,当您的activity首次开始,它达到系统的前台和接受用户的聚焦。在这个过程之中,Android系统调用一系列的生命周期方法来设置用户界面和其他组件。如果用户开启一个行为动作,开启另一个活动或者切换到另一个界面,系统则会在您的活动中调用另一组生命周期的方法,因为它进入了后台(活动不再是可见的了,但是实例和它的状态依然保持不变)。
Within the lifecycle callback methods, you can declare how your activity behaves when the user leaves and re-enters the activity. For example, if you‘re building a streaming video player, you might pause the video and terminate the network connection when the user switches to another app. When the user returns, you can reconnect to the network and allow the user to resume the video from the same spot.
在生命周期回调方法中,当用户离开和再次进入是,您可以声明您的活动行为。举个例子来说,如果您正在创建一个流媒体视频播放器,当用户切换到另一个应用程序时,您可能会暂停播放器以及终止网络连接,当用户返回时,你可以重新连接到网络,允许用户从离开时的同一时刻恢复视频。
This class explains important lifecycle callback methods that each Activity
instance receives and how you can use them so your activity does what
the user expects and does not consume system resources when your activity doesn‘t need them.
这类解释了重要的生命周期回调方法,这类方法是每个Activity
实例接收和如何使用它们,这样达到您的活动用户的期望,以及当您的活动时不需要他们不消耗系统资源。
Managing the Activity Lifecycle 管理活动的生命周期,布布扣,bubuko.com
Managing the Activity Lifecycle 管理活动的生命周期
原文:http://blog.csdn.net/xia09222826/article/details/27309859