Android - Shared element transitions with calling activity finish()
You can finish your activity in the onStop function, if you only want this to happen when you transition from A to B then create a flag and set it after you call startActivity(ctx,intent, bundle):
@Override
public void onStop() {
super.onStop();
if(mShouldFinish)
finish();
}
Make sure when you are done with activity B to call finish() and not finishAfterTranstion() since activity A is no longer there
After finishing the activity A, shared element in B might hang in screen if you press back. Set transitionName to null in ActivityB.onEnterAnimationComplete
to avoid this.
This is maybe late but I had the same issue. What worked for me is:
supportFinishAfterTransition();
This is included in the support library and works like charm.
PS: you don't needto call finish()
when you call supportFinishAfterTransition()
.
UPDATE
Much better and simpler way
ActivityCompat. finishAfterTransition(this);
<3 support library.