I have a gallery app here. GalleryActivity contains recyclerView loaded with image thumbnails. On clicking the thumbnail, it starts SlideshowActivity for enlarged image. I'm using SharedElements transition, I know how to use it and everything is working fine. But something is bothering me for quite some time.
GalleryActivity starts in portrait mode. After going into SlideshowActivity, user rotates the phone into landscape mode and pressed back. Below is the sequences which are called.
SlideshowActivity | finishAfterTransition
GalleryActivity | onActivityReenter
// I call supportPostponeEnterTransition() in onActivityReenter
GalleryActivity | onStart
GalleryActivity | onConfigurationChanged
// App will hang here if I do not call supportStartPostponedEnterTransition() by now
SlideshowActivity | finish
// Back transition starts here
SlideshowActivity | onPause
GalleryActivity | onStop
GalleryActivity | onDestroy
GalleryActivity | onCreate
GalleryActivity | onStart
GalleryActivity | onActivityResult
GalleryActivity | onResume
This sequence just doesn't make sense to me because after the back transition is completed, GalleryActivity is destroyed and recreated, which causes blinking and reload. Shouldn't onActivityReenter be called after GalleryActivity is recreated, then we can plan for back transition with the new view laid out?
Right now, in order to avoid this, I am handling the configuration change of GalleryActivity by myself via Manifest android:configChanges="orientation|screenSize
. As I know, we should avoid doing that. Is this one of the cases where we need to?
In this case, the sequence will become below and everything works just fine.
SlideshowActivity | finishAfterTransition
GalleryActivity | onActivityReenter
// I call supportPostponeEnterTransition() in onActivityReenter
GalleryActivity | onStart
GalleryActivity | onConfigurationChanged
// I call supportStartPostponeEnterTransition() once the view is ready
SlideshowActivity | finish
SlideshowActivity | onPause
GalleryActivity | onActivityResult
GalleryActivity | onResume
Kindly let me know if there is a proper way of handling this, without handling onConfigurationChanged() by myself.