Activity的API

Managing the Activity Lifecycle

DEPENDENCIES AND PREREQUISITES

YOU SHOULD ALSO READ

TRY IT OUT

Download the demo

ActivityLifecycle.zip

As a user navigates through, out of, and back to your app, theActivity 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).

管理界面的生命周期

作为一个使用者,浏览,退出,回到你的应用,你的界面的实例的生命周期不断变化。例如,当你的界面第一次开始执行时,它到达了前台,并引起了我们的注意。在这个过程中,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.

在生命周期中调用的方法,你能声明你的界面活动,当你的使用者离开或者重行进入这个界面时。例如,当你正在完成一个音乐播放器,你可能暂停了它,并终止了网络连接,当使用者切换到另一个应用时。当用户返回该应用时,他能够继续重行连接网络,并保持播放器中的音乐进度。


这篇文章解释了每个生命周期对应方法的重要性,应用实例指导我们如何去使用自己的应用,当我们想要时可以的倒塌,不需要时就释放这些应用占据的资源。



Lessons


Starting an Activity
Learn the basics about the activity lifecycle, how the user can launch your app, and how to perform basic activity creation.
学习最基本的生命周期,你如何在你的应用中使用它们,并制作一个应用。
Pausing and Resuming an Activity
Learn what happens when your activity is paused (partially obscured) and resumed and what you should do during these state changes.
学习在暂停时,你的应用发生了什么(部分遮掩),在重启后,在你的应用变化时,你应该做什么。
Stopping and Restarting an Activity
Learn what happens when the user completely leaves your activity and returns to it.
学习你完全离开你的界面在会到他时,发生了什么。
Recreating an Activity
Learn what happens when your activity is destroyed and how you can rebuild the activity state when necessary.
学习当你的应用被销毁时,当你需要时,你重行建立一个应用又发生了什么。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值