jueves, 11 de marzo de 2010

Issue in 2.1: onStop()/onDestroy() delayed...

Dianne Hackbor has recently posted at groups.google.com/group/android-developers this about the activities lifecycle in Android 2.1.

Hi, there is an issue in 2.1 with the new launcher that causes the onStop()/onDestroy()to be delayed longer than typical when going back to home. Note these are not delayed -forever-, but just until later in the future (when the next activity switch happens).

These methods are defined to happen at "some time in the future" so technically it is not really broken, but this is certainly not the desired behavior here. This will befixed in the next release.

Fwiw, this happened because the new launcher has a special surface view on top of itself to display the 3d all apps, and this caused the window manager to be confused and not realize that the app behind it had been hidden so it could then be stopped/destroyed.


It looks like these basic methods in android activities have not the desired behavior.
For example in my case when the current activity called the onStop() method it should kill a background service, but because this issue as this method has a delay, when the OS really calls onStop() it caused a disaster in my application.

Solution: instead of using onStart() and onStop() in order to manage the background service I use the onResume() and onPause() methods.

No hay comentarios:

Publicar un comentario