Could someone provide a description of what happens when an
Activity calls its
Does it exit immediately, or does it complete the function from which it was called?
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Does it exits immediately or completes
the function from which it was called
The method that called
finish() will run to completion. The
finish() operation will not even begin until you return control to Android.
Every life cycle event like
onDestroy of an Activity is always called on a single thread – The “Main thread”.
In short this thread is backed by a Queue into which all the activity events are getting posted.
This thread can execute all these events in the order of insertion.
If you are calling
finish() in one of the life cycle callbacks like
onCreate()…a “finish” message will get added to this queue but the thread is not free to pick & execute “finish” action
until currently executing method returns i.e Thread is freed from current task.
ondestroy() is the final call you receive before your activity is destroyed.
This can happen either because the activity is finishing (someone called
finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the
If there are two activities A and B. And your flow is going from A > B; and B=A calls
The method where you called
finish() from will execute as Mark mentioned. And flow of callbacks will be as followed –
onResume()of Activity B
- Then, comes the real difference. If you did not call
activity A; only
Activity Awill be called here. While, in this case, where we called
Activity A; So
onDestroy()both will be called for
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0