Android学习 多读官网,有益健康--Activity状态 onPause()

今天抽空学习了下安卓官网,对安卓的Activity的生命周期有了更深的理解。

http://developer.android.com/training/basics/activity-lifecycle/pausing.html

 

When the system calls onPause() for your activity, it technically means your activity is still partially visible, but most often is an indication that the user is leaving the activity and it will soon enter the Stopped state. You should usually use the onPause() callback to:

  • Stop animations or other ongoing actions that could consume CPU.
  • Commit unsaved changes, but only if users expect such changes to be permanently saved when they leave (such as a draft email).
  • Release system resources, such as broadcast receivers, handles to sensors (like GPS), or any resources that may affect battery life while your activity is paused and the user does not need them.

 

。。。。

However, you should avoid performing CPU-intensive work during onPause(), such as writing to a database, because it can slow the visible transition to the next activity (you should instead perform heavy-load shutdown operations during onStop()).

 

系统调用了onPause()方法时,Activity处于半可见状态,多数情况下意味着用户要离开这个Activity,很快进入停止状态。通常我们在onPause回调里面执行

1、停止动画

2、提交未保存的东西,比如草稿邮件

3、释放系统资源,如广播接收器、GPS等等,或者可能影响电池生命的资源等等。

。。。。

然而,应该避免在onPause回调中进行消耗CPU的操作,比如写数据库,因为这样会使进入下一个Activity的转换动画造成延迟,最好把这些操作房子onStop方法中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值