10

Imagine that I have an Activity A and I'm starting a new activity B from that one.

What will be the Activities lifecycle side-by-side?

 1. A: onCreate 
 2. A: onStart 
 3. A: onResume

on A => startActivity(B)

 4. B: onCreate
 5. B: onStart

 6. A: onPause

 7. B: onResume

 8. A: onStop

Is this correct?

neteinstein
  • 17,529
  • 11
  • 93
  • 123
  • 4
    Testing this with `Log.d()` and `logcat` will take less time than waiting for an answer to this question... – Turbo J Apr 10 '12 at 18:15
  • I was looking for a Android Developer site reference to confirm it, as the answer provided. My bad for not saying so... – neteinstein Apr 10 '12 at 18:22

2 Answers2

15

Almost correct, just a minor difference. first A.onPause() and then B.onCreate()... etc

A: onCreate
A: onStart
A: onResume

on A => startActivity(B)

A: onPause
B: onCreate
B: onStart
B: onResume
A: onStop

Check this link for complete details

http://developer.android.com/guide/topics/fundamentals/activities.html#CoordinatingActivities

neteinstein
  • 17,529
  • 11
  • 93
  • 123
Shubhayu
  • 13,402
  • 5
  • 33
  • 30
4

There is a beautiful app in the developer's site which shows the activity lifecycle, pls have a look at it.You can download the app's source code here. Thought it might help someone :).

vin
  • 337
  • 2
  • 18
  • 2
    I can attest to this. This application, which comes in source code form and cannot be imported but rather should be "created from existing source, is absolutely wonderful and a huge must for any Android programmer trying to master the art of handling the life-cycle of activities. +1 and thank you for bringing this to my attention as I just didn't know about it before. – an00b Aug 09 '12 at 13:09