1

可能重复:
Android Activity 生命周期 - 所有这些方法的用途是什么?

我有一个名为 main 的活动menuActivity和另一个名为birthDate.

当我运行应用程序时,它menuActivity成为活动应用程序,当我单击一个按钮时,第二个应用程序成为活动应用程序,即birthDate.

我的问题是:

当第一个活动变得活跃时,另一个活动进入后台,主要活动进入前台,我必须实施哪种方法?OnResume还是OnCreate什么?

4

6 回答 6

5

onResume .. 检查以下http://developer.android.com/training/basics/activity-lifecycle/index.html 在此处输入图像描述

于 2012-12-19T07:39:59.990 回答
4

尝试阅读Android文档,了解Activity生命周期

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

像下面链接中的图片

在此处输入图像描述

于 2012-12-19T07:40:08.757 回答
4

您必须实施 onResume。

看看这个 Android Activity 生命周期

在此处输入图像描述

于 2012-12-19T07:40:28.317 回答
2

您应该阅读http://developer.android.com/reference/android/app/Activity.html 您正在寻找的方法是 onResume()。

于 2012-12-19T07:40:41.390 回答
2

如果您想在 Activity 恢复时执行某些操作,则必须将代码放入其中,onResume()因为onResume()每次 Activity 进入前台时都会调用该方法。onCreate()在 Activity 生命周期中只调用一次。

于 2012-12-19T07:40:52.880 回答
0

系统中的活动作为活动堆栈进行管理。当一个新的 Activity 启动时,它被放置在栈顶并成为正在运行的 Activity——之前的 Activity 始终保持在它的下方,直到新的 Activity 退出后才会再次来到前台。

一个活动基本上有四种状态:

**If an activity in the foreground of the screen (at the top of the stack), it is active or running.**

**If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations.**

**If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.**

**If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or simply killing its process. When it is displayed again to the user, it must be completely restarted and restored to its previous state.**

下图显示了 Activity 的重要状态路径。方形矩形表示您可以实现的回调方法,以便在 Activity 在状态之间移动时执行操作。彩色椭圆是 Activity 可以处于的主要状态。

在此处输入图像描述

于 2012-12-19T07:54:29.777 回答