Android life cycle activities [duplicate]

萝らか妹 提交于 2019-12-13 01:27:52

问题


Possible Duplicate:
Android Activity Life Cycle - What are all these methods for?

I have an activity which is main called menuActivity and another activity which called birthDate.

When I run the application the menuActivity become the active one and when I click on a button the second one become the active one which is the birthDate.

My question is:

When the first activity become active another activity goes to background and main activity comes to forground , which method do I have to implement ? OnResume or OnCreate or what?


回答1:


onResume.. check the following http://developer.android.com/training/basics/activity-lifecycle/index.html




回答2:


Try read Android Document and understand Activity life cycle

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

like below image from link




回答3:


It's onResume that you will have to implement.

Take a look at this Android activity life cycle




回答4:


You should read http://developer.android.com/reference/android/app/Activity.html The method you're looking for is onResume().




回答5:


If you want to do some action when Activity resumes you have to put your code inside onResume() because onResume() is the method that is called everytime your Activity comes to foreground. onCreate() is only called once in the Activity lifetime.




回答6:


Activities in the system are managed as an activity stack. When a new activity is started, it is placed on the top of the stack and becomes the running activity -- the previous activity always remains below it in the stack, and will not come to the foreground again until the new activity exits.

An activity has essentially four states:

**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.**

The following diagram shows the important state paths of an Activity. The square rectangles represent callback methods you can implement to perform operations when the Activity moves between states. The colored ovals are major states the Activity can be in.



来源:https://stackoverflow.com/questions/13947587/android-life-cycle-activities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!