Question about usage onStart() of Activity. I read few articles about Activity Life Cycle (Android activity life cycle - what are all these methods for?, Difference between onStart() and onResume(), etc), looked at code samles, but I can't imagine any practical situation where method onStart() may be used. In my opinion onCreate() and onResume() cover 100% situations that may be encountered by developers. Can somebody give an example where this method can be useful?
Asked
Active
Viewed 699 times
1
-
2http://stackoverflow.com/questions/8515936/android-activity-life-cycle-what-are-all-these-methods-for – Guillaume Jun 13 '13 at 13:10
1 Answers
1
So onStart is called after an onStop and onResume after onPause so lets imagine you're on an activity an alertDialog Pops here your activity is paused here so on Pause when the AlertDialog goes you onStart is not called. Second situation you're in an activity you go on an other here your activity is Stopped cause you totally lost the focus and then when you come back to this activity onStart is called! Can you see the difference ?

Maxime Cancellara
- 26
- 2
-
I'm not really sure I understood your answer. Imagine you in activity A1, and run activity A2. Will be next events: A1.onPause, A2.onCreate, A2.onStart, A2.onResume, A1.onStop. Than you click back, and will be next events: A2.onPause, A1.onRestart, A1.onStart, A1.onResume, A2.onStop, A2.onDestroy. So onResume ALWAYS fallow onStart, and you can do alll things in onResume. – anber Jun 13 '13 at 14:44
-
Nope! cause every time you will resume you'll execute all the code in onResume that's why its better to implement just parts needed in onStart. Imagine an application wich displays current pictures you have in you database,when you click on a picture it opens a bigger view of it but you stay on this activity here you're on pause when you change activity to go next activity (here you're on stop) and come back to this one you want to reload in case you added a picture, if you do this in onResume you'll do that every time the bigger view of picture clicked pops.Can you understand difference now? – Maxime Cancellara Jun 13 '13 at 15:00
-
You want to tell that it is possible situation, when will be called "onStart()" than "onResume()", after than you show dialog with something, at that moment in activity will be called "onPause()", after that you close it and will be called only "onResume()" without "onStart()" ? it is difficult to understand exactly the situation that you described, you can update your answer and give a piece of code or schematic? – anber Jun 13 '13 at 16:11
-
Ok i'll try. Imagine you show an alert dialog like dat : dialog.show(); here the dialog comes in front of your current activity when your activity is not in the foreground anymore onPause is called but you still can see it on Stop is not called then when you do dialog.dismiss() onResume is executed but not on start because onStop was not called it is called only when your activity totally disappears so when you can't see it anymore one your screen (for instance when you start an other) – Maxime Cancellara Jun 14 '13 at 06:16
-
1Thanks a lot for your patience, now I see the difference. Also a good example would be to run a transparent Actyvity, from this question http://stackoverflow.com/questions/2176922/how-to-create-transparent-activity-in-android – anber Jun 14 '13 at 08:36