0

Activity A has a small ImageSwitcher that shows a stream with images and information about the current image.

When pressing the current image activity B opens with the image in fullscreen. You can continue to watch the image stream here.

Pressing the image here finishes this activity and goes back to A.

There is a image transition from A to B where the smaller image becomes bigger to fit the image in B.

When going back to A from B the image becomes smaller to fit in A.

The transitions works smoothly with just using

Intent intent = new Intent(this, BActivity.class);
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, imageSwitcher,"imageInStream");
startActivity(intent, options.toBundle());

But if the image shown in activity B has changed to the next in the stream, then when going back to activity A the animation ends with a brief flicker of the previous image.

I have tried with delaying the transition with

protected void onResume() {
    super.onResume();
    postponeEnterTransition();
    // loading the image
    imageSwitcher.setImageDrawable(new BitmapDrawable(getResources(), imageBitmap));
    startPostponedEnterTransition();
}

I have also tried to put the startPostponedEnterTransition call in the post method of imageSwitcher, but the flickering persists.

So for some reason it seems like the imageSwitcher has not changed image yet, but I have no idea how to resolve this.

Rickard Lindroth
  • 697
  • 2
  • 6
  • 14
  • postponeEnterTransition() will do nothing for you in this case. That is for entering a new activity (i.e. from startActivity). You are Returning to an already running Activity A. I'm sure there are other ways of handling this, but how I have solved a similar issue in the past is by not returning to the already running Activity A, but instead finishing Activity A and startActivity back to Activity A, to perform a new Enter shared element transition. In my case, I needed to do this, because the shared element needed to change position and bounds on my Activity A, when returning to it. – Jason Grife May 30 '17 at 16:35
  • Starting to load the new image in onActivityReenter solved it. But it makes me nervous how it will behave on slower devices. Killing the activity is not really an option as if I start messing with the activity stack it will turn quite complex. – Rickard Lindroth May 31 '17 at 08:53

0 Answers0