您的位置:首页 > 其它

Activity的onPause()官方文档翻译

2015-08-19 11:43 295 查看


protected void onPause ()

Added in API level 1

Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed. The counterpart to
onResume()
.
当Activity即将进入后台(失去焦点)且还没有被销毁时该方法将会作为activity生命周期的一部分被调用。该方法与onResume()方法匹配。

When activity B is launched in front of activity A, this callback will be invoked on A. B will not be created until A's
onPause()
returns,
so be sure to not do anything lengthy here.
当由activity A跳转到activity B时,activity A将会调用该onPause()方法。直到A的onPause()方法执行完毕activity B才会被创建,因此不要在onPause()方法中执行比较耗时的操作。

This callback is mostly used for saving any persistent state the activity is editing, to present a "edit in place" model to the user and making sure nothing is lost if there are not enough resources
to start the new activity without first killing this one. This is also a good place to do things like stop animations and other things that consume a noticeable amount of CPU in order to make the switch to the next activity as fast as possible, or to close
resources that are exclusive access such as the camera.
这个回调方法主要用于保存一些activity正在执行的持久化的数据(可以保存到内存或sd卡),向用户提供了一种“就地编辑”的模式以确保在启动新的activity因没有足够的资源需要销毁当前activity时没有数据的丢失。为了保证Activity间的跳转尽可能的流畅,我们可以在onPause()方法中执行关闭动画或者停止非常耗费CPU的操作,或者关闭一些独享资源(设备资源),例如相机(相机不可以同时被多次调用,释放相机资源:Camera.release())。

In situations where the system needs more memory it may kill paused processes to reclaim resources. Because of this, you should be sure that all of your state is saved by the time you return from
this function. In general
onSaveInstanceState(Bundle)
is
used to save per-instance state in the activity and this method is used to store global persistent data (in content providers, files, etc.)
当系统内存不足时可能会销毁处于暂停状态的进程从而释放内存。因此,你应确保在onPause()方法中保存所有状态。通常情况下onSaveInstanceState(Bundle)用于保存activity的中每一个临时数据,而onPause()用于保存全局的持久化数据。

After receiving this call you will usually receive a following call to
onStop()
(after
the next activity has been resumed and displayed), however in some cases there will be a direct call back to
onResume()
without
going through the stopped state.
在执行完onPause()方法后通常会执行其后的onStop()方法(在下一个待启动的activity执行完onCreate(),onStart(),onResume()后),然而有些时候onPause()执行完后不用执行其后的onStop()方法就可返回执行onResume()方法(例如:Activity中弹出弹窗和关闭弹窗的过程:onResume > onPause() >onResume());

Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.
调用该方法时必须也要调用父类的方法,否则会抛出异常。

See Also

onResume()

onSaveInstanceState(Bundle)

onStop()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: