android onpause时动画出错,Android onPause()和onStop()区别

Paused

谷歌官方的解释是:Another activity is in the foreground and has focus, but this one is still visible. That is, another activity is visible on top of this one and that activity is partially transparent or doesn’t cover the entire screen. A paused activity is completely alive (the Activity object is retained in memory, it maintains all state and member information, and remains attached to the window manager), but can be killed by the system in extremely low memory situations.

另外一个activity(BActivity)在前台显示并且获取了焦点,但是之前的activity(AActivity)还是可见的。即,BActivity在AActivity的上面并且BActivity是部分透明的或者不覆盖整个屏幕。一个处于paused状态的Activity 是完全活着的,(Activity对象保留在内存中,它保持着所有的状态和成员信息并且和windows Manager保持着相连接),但可以在低内存的时候被系统杀死。

Stopped

谷歌官方的解释是:The activity is completely obscured by another activity (the activity is now in the “background”). A stopped activity is also still alive (the Activity object is retained in memory, it maintains all state and member information, but is not attached to the window manager). However, it is no longer visible to the user and it can be killed by the system when memory is needed elsewhere.

一个activity(AActivity)完全被另一个Activity(BActivity)挡住(AActivity在后面)。一个处于Stopped状态的activity 也是任然活着的(Activity对象保留在内存中,它保持所有的状态和成员信息,但是和Stopped不同的一点就是没有和Windows Manager相连接),然而它不再对用户可见,它可以在任何需要内存的地方被杀死。

OnPause()

官方对OnPause()方法的解释如下:

Called when the system is about to start resuming another activity. This method is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, and so on. It should do whatever it does very quickly, because the next activity will not be resumed until it returns.

Followed either by onResume() if the activity returns back to the front, or by onStop() if it becomes invisible to the user.

当系统即将恢复另一个activity的时候,此方法通常用于提交一些未保存的持久性数据,停止动画和一些可能会消耗CPU的东西,它应该尽一切可能快的完成,因为接下来的Activity在OnPause()返回之前不会被恢复。

接下来要么运行onResume()方法(如果Activity返回到前台),要么运行onStop()方法(如果Activity变得对用户不可见)。

Called when the activity is no longer visible to the user. This may happen because it is being destroyed, or because another activity (either an existing one or a new one) has been resumed and is covering it.

Followed either by onRestart() if the activity is coming back to interact with the user, or by onDestroy() if this activity is going away.

onStop()

Called when the activity is no longer visible to the user. This may happen because it is being destroyed, or because another activity (either an existing one or a new one) has been resumed and is covering it.

Followed either by onRestart() if the activity is coming back to interact with the user, or by onDestroy() if this activity is going away.

当activity不再对用户可见时调用此方法,这方法可能被调用,因为它即将被销毁,或者因为另外一个Activity(可能是一个已经存在的Activity或者一个新的Activity)已经被恢复然后覆盖了这个activity。

接下来如果这个activity 即将再次与用户交互(我觉得是再次对用户可见的意思),就会调用onRestart()方法,如果这个Activity即将死亡的话,就会调用onDestroy()方法。

上面是Activities中对OnPause()和onStop()的定义和解释。

在Managing the activity lifeCycle中,对它们的描述是:

Generally, you should not use onPause() to store user changes (such as personal information entered into a form) to permanent storage. The only time you should persist user changes to permanent storage within onPause() is when you’re certain users expect the changes to be auto-saved (such as when drafting an email). 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()中将例如一个表单内容保存到物理内存中,只有当你确认用户引起的变化是必须必须被自动保存的时候(例如起草一封电子邮件)。然而你应该避免在onPause()的时候做一些占用CPU很长的工作,比如写数据库,因为它会减缓下一个Activity出现的过程(意思就是要尽可能快地运行完onPause()),你应该在onStop的时候干这个事情。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值