Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android onStop() not being called when starting a new activity in multi window mode

I am trying Android N multi window feature and I have found myself confused when starting a new activity. The problem is that when I start a new Activity, the onStop() callback is not being fired and when I press the back button from this new activity to return to the previous one, the previous one's onStart() callback is not being fired either.

Does anyone know what is happening?

--- Edited

It seems like that ActivityOptionsCompat.makeSceneTransitionAnimation has something to do with it.

like image 282
Augusto Carmo Avatar asked Aug 08 '16 13:08

Augusto Carmo


People also ask

Is onStop guaranteed to be called?

The onStop() method is used to save application data. These methods are guaranteed to be called before the activity is terminated. If the user switches back to application which has been terminated by the system, it is restarted.

When onStop method is called in Android?

onStop() Called when the activity is no longer visible to the user. Either because another Activity has resumed, and is covering this one, an existing activity is coming to the foreground, or the activity is about to be destroyed.

Why it is required to have onPause () and onStop () callbacks separately?

Once your activity is stopped, the system might destroy the instance if it needs to recover system memory. In extreme cases, the system might simply kill your app process without calling the activity's final onDestroy() callback, so it's important you use onStop() to release resources that might leak memory.

When only onDestroy is called for an activity without onPause () and onStop ()?

onPause() and onStop() will not be invoked if finish() is called from within the onCreate() method. This might occur, for example, if you detect an error during onCreate() and call finish() as a result. In such a case, though, any cleanup you expected to be done in onPause() and onStop() will not be executed.


1 Answers

Here is the android-lifecycle:

AndroidLifecycle

If you call another app in multi window mode, your application is still "partially visible", so onPause() is being called, but onStop() not.

At restart it's the same: onResume() is being called, but onStart() isn't.

like image 50
UeliDeSchwert Avatar answered Sep 19 '22 15:09

UeliDeSchwert