Android生命周期活动

时间:2012-12-19 07:38:03

标签: android lifecycle oncreate onresume

  

可能重复:
  Android Activity Life Cycle - What are all these methods for?

我有一个名为menuActivity的主要活动和另一个名为birthDate的活动。

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

我的问题是:

当第一个活动变为活动状态时,另一个活动转到后台,主要活动转到forground,我必须实现哪种方法? OnResumeOnCreate还是什么?

6 个答案:

答案 0 :(得分:5)

答案 1 :(得分:4)

尝试阅读Android文档并了解活动生命周期

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

如下图链接

enter image description here

答案 2 :(得分:4)

这是onResume,你必须实现。

看看这个Android活动生命周期

enter image description here

答案 3 :(得分:2)

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

答案 4 :(得分:2)

如果您想在Activity恢复时执行某些操作,则必须将代码放在onResume()中,因为onResume()是每次Activity到达前台时调用的方法。 onCreate()仅在活动生命周期中调用一次。

答案 5 :(得分:0)

系统中的活动作为活动堆栈进行管理。当一个新活动开始时,它被放置在堆栈顶部并成为正在运行的活动 - 前一个活动始终保持在堆栈中低于它,并且在新活动退出之前不会再次到达前台。

活动基本上有四种状态:

**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在状态之间移动时可以实现的回调方法。彩色椭圆是活动所在的主要州。

enter image description here