【问题标题】:Android life cycle activities [duplicate]Android生命周期活动[重复]
【发布时间】:2012-12-19 07:38:03
【问题描述】:

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

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

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

我的问题是:

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

【问题讨论】:

标签: android lifecycle oncreate onresume


【解决方案1】:
【解决方案2】:

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

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

如下图链接所示

【讨论】:

    【解决方案3】:

    您必须实施 onResume。

    看看这个 Android Activity 生命周期

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        【解决方案5】:

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

        【讨论】:

          【解决方案6】:

          系统中的活动作为活动堆栈进行管理。当一个新的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 可以处于的主要状态。

          【讨论】:

            猜你喜欢
            • 2013-01-13
            • 2011-12-18
            • 1970-01-01
            • 1970-01-01
            • 2014-09-26
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多