1

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?

Community
  • 1
  • 1
Android Developer
  • 1,039
  • 1
  • 9
  • 33
  • Related thread - http://stackoverflow.com/questions/8515936/android-activity-life-cycle-what-are-all-these-methods-for?rq=1 – KV Prajapati Dec 19 '12 at 07:43

6 Answers6

5

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

Nermeen
  • 15,883
  • 5
  • 59
  • 72
4

Try read Android Document and understand Activity life cycle

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

like below image from link

enter image description here

Dinesh
  • 6,500
  • 10
  • 42
  • 77
4

It's onResume that you will have to implement.

Take a look at this Android activity life cycle

enter image description here

Infinity
  • 3,695
  • 2
  • 27
  • 35
2

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

galex
  • 3,279
  • 2
  • 34
  • 46
2

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.

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
0

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.

enter image description here

G M Ramesh
  • 3,420
  • 9
  • 37
  • 53