是的onStop()总是美元的的onPause pceded p $() [英] Is onStop() always preceded by onPause()

查看:144
本文介绍了是的onStop()总是美元的的onPause pceded p $()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读,来的onStop()的调用始终是()通过调用pceded到的onPause $ P $无论方案是什么。参考图1在 http://developer.android.com/training/基础/活动的生命周期/ stopping.html

I have read that a call to onStop() is always preceded by a call to onPause() no matter what the scenario is. Reference: Figure 1 on http://developer.android.com/training/basics/activity-lifecycle/stopping.html

我们知道,一个活动暂停时,它不具有用户的焦点,但它仍然部分地可见的,并且它被停止时,它是不可见的。

We know that an activity is paused when it does not have user's focus but it still partially visible, and it is stopped when it is not visible at all.

现在,当用户在一个活动,从最近的应用程序窗口中选择并进入另一个应用程序的情况下,该活动将从进入恢复/运行停止状态。没有中间暂停状态。

难道不是吗?

什么是好的理由总是有之前的onStop在onPause()()。我们可以的onStop()什么是做的onPause做()。 为什么我们总是需要的onPause()之前的onStop()?

What is the good reason for always having onPause() before onStop(). We can do in onStop() what is done in onPause(). Why do we always need onPause() before onStop()?

推荐答案

的onPause()总是被调用。这是保证。如果您需要保存在您的活动的任何状态,你需要将其保存在的onPause()的onStop()可在的onPause被称为(),也可能不会。视情况而定。

onPause() is always called. This is guaranteed. If you need to save any state in your activity you need to save it in onPause(). onStop() may be called after onPause(), or it may not. Depends on the situation.

有大量的生命周期方法。你并不需要重写所有的人。你只需要重写,你需要(或希望)自定义行为的活动的人。有很多的生命周期方法,因为不同的应用有不同的要求。一个活动的生命周期是证据充分的乖巧。这允许程序员把code究竟需要的地方,根据应用的特殊要求。

There are a lot of lifecycle methods. You don't need to override all of them. You only need to override the ones where you need (or want) to customize the behaviour for your activity. There are a lot of lifecycle methods because different applications have different requirements. The lifecycle of an Activity is well-documented and well-behaved. This allows programmers to put the code exactly where it is needed, based on the particular requirements of the application.

您已经要求

什么是好的理由总是有之前的onStop在onPause()()。
  我们可以的onStop()什么是的onPause()来完成事情。

What is the good reason for always having onPause() before onStop(). We can do in onStop() what is done in onPause().

的onPause()总是叫你的活动,如果它是在前台时,Android的希望别的做一些事情。它可以启动另一个活动可能导致您的活动的的onStop()获取调用。这可能只是叫 onResume()您的活动。这可能只是杀了你的过程中没有调用任何你更多的生命周期方法。

onPause() is always called on your Activity if it is in the foreground when Android wants to do something else. It may start another Activity which may result in your Activity's onStop() getting called. It may just call onResume() on your activity. It may just kill your process without calling any more of your lifecycle methods.

由于的onStop()不能保证被调用,你不能总是做的onStop()什么是做的onPause()

Since onStop() is not guaranteed to be called, you can't always do in onStop() what is done in onPause().

在大多数活动,你会发现,你将需要把code在 onResume()的onPause()。通常你不必做任何事情的onStop()在onStart() onRestart()

In most Activities, you will find that you will need to put code in onResume() and onPause(). You usually don't have to do anything in onStop(), onStart() or onRestart().

这篇关于是的onStop()总是美元的的onPause pceded p $()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆