您的位置:首页 > Web前端

Managing the Activity Lifecycle

2014-05-28 21:04 441 查看
Activity生命周期的管理

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系统调用一系列的生命周期方法去在activity上设置用户界面和其他组件。如果用户执行一个动作,开启另一个activity或切换到另一个应用程序,系统在你的activity中调用另一组生命周期方法,而且后台进行(活动不再是可见的,但实例及其状态保持不变)。

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.

在生命周期回调方法中,当用户离开或者重新进入该activity时你可以声明你的activity行为。例如,如果你正在创建一个流媒体视频播放器,当用户切换到另一个应用程序时,你应该暂停视频和终止网络连接。当用户返回时,你要重新连接到网络,允许用户从视频暂停的地方继续观看。

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实例接收和如何使用它们,这样你的activity做用户所期望的,当你的活动不需要它们时也不消耗系统资源。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: