7

Which activity method is called first in Android? For example viewWillAppear is called first in case of IPhone.
Also can someone tell me when I come back from an activity to previous activity, which method is called first? I don't want to load everything again and again each time I come back to an activity.

Thanks,
Stone

4 Answers4

21

When you enter your app, the life cycle flow will be like this:

onCreate() -> onStart() -> onResume()

Now if you are using an intent to move from your current Activity to the next Activity, these are the methods of the current activity that will be executed:

onPause() -> onStop()

When you come back to the same activity(e.g., using back key event), these are the methods of the current activity that will be executed:

onStart() -> onResume()

And when you exit your app, the flow goes like this:

onPause() -> onStop() -> onDestroy()

Erick Filho
  • 1,962
  • 3
  • 18
  • 31
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
2

All the information you need is provided in the documentation on Activity lifecycle. You should read it as it is important to understand. Incidentally, viewWillAppear is not called first on the iPhone. There are a couple methods called before that.

glorifiedHacker
  • 6,410
  • 2
  • 22
  • 26
2

i guess you are new to android. here is a link which describes about the life cycle of an activity. LINK

in short onCreate is called first and when you comeback from an activity onResume will be called. onResume will also be called the first time as well. onPause will be called whenever an activity goes background.

Samuel
  • 9,883
  • 5
  • 45
  • 57
1

if the prevoius Activity has been killed by OS when its gone background then again onCreate() method is called. or else its onResume() method which gets called..

ngesh
  • 13,398
  • 4
  • 44
  • 60