Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onStart of new Activity is called before onStop of parent

I've got an application. I use startActivity() to start activity.

Can anyone actually tell me why system is calling onStart() of new Activity first, instead of parents onStop()? Is that even possible (without system bug)?

I've found Fragment onStop() being called directly after onStart() - WHY? answer, but I got nothing in common with Fragments and using android-support library. I'm stuck because I'm using RoboSpice and it must contain proper, synchronized methods in onStart and onStop. I can't because system is calling it in wrong order.

I'm using GCM and Analytics libraries as well in this application.

like image 852
cadavre Avatar asked Jun 20 '13 13:06

cadavre


People also ask

Is onPause always called before onStop?

onPause() is always called. This is guaranteed. If you need to save any state in your activity you need to save it in onPause() . onStop() may be called after onPause() , or it may not.

What comes after onStart () in activity life cycle?

The onStart() method is then called, followed by onResume() . In this lifecycle, the user can interact with the UI components.

Which method is called immediately after the onStart method?

The onStart() method completes very quickly and, as with the Created state, the activity does not stay resident in the Started state. Once this callback finishes, the activity enters the Resumed state, and the system invokes the onResume() method.

What is called when the activity is first created?

1. onCreate() This is the first callback and called when the activity is first created. 2. onStart()


1 Answers

If you have a read of the Activity Lifecycle documentation onStop is only called when the current activity is replaced by a new (or previous) one.

For that to happen the other application has to start or resume... otherwise there would be a gap

onPause of the current activity is (I would expect) called before the onStart of the replacing Activity

like image 76
Paul D'Ambra Avatar answered Oct 20 '22 11:10

Paul D'Ambra