I need help about transition between activities:
I have two activities A and B and both have a ViewPager with the same image list. Every page has an ImageView with the transitionName
equals to image_x where x is the page index.
A starts activity B calling ActivityOptionsCompat.makeSceneTransitionAnimation
and the enter transition is totally fine.
The problem is the following: when I close activity B, the exit transition does not initialize the view pager of activity A at the same position of B.
When user closes B, the latter sets the current page position in the result. In onActivityResult
of activity A, I call the setCurrentItem
and the behavior is showed in the gif.
Is there a way to update activity A before the exit transition starts?
You should be able to do achieve that if you use setCurrentItem
in the onActivityReenter
instead of in onActivityResult
(in your Activity
A
).
Just be sure you:
Activity
B
, set the result (either with setResult(int resultCode)
or setResult(int resultCode, Intent data)
)supportFinishAfterTransition()
(or finishAfterTransition()
) instead of regular finish()
to "close" the Activity
B
.To summerize:
in Activity
B
:
public void close(){
Intent data = new Intent();
data.putExtra(KEY_CURRENT_ITEM, mFullscreenViewPager.getCurrentItem());
setResult(RESULT_CODE, data);
supportFinishAfterTransition();
}
in Activity
A
:
@Override
public void onActivityReenter(int resultCode, Intent data) {
super.onActivityReenter(resultCode, data);
if (data.hasExtra(KEY_CURRENT_ITEM)){
mViewPager.setCurrentItem(data.getIntExtra(KEY_CURRENT_ITEM, 0), false);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With