问题
I have an Activity A from there I open Activity B, and pass the shared element to it. It animates the transition fine, but when I go back to Activity A and then go to Activity B again which is still in the stack using
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
The shared element transition is not run.
With regular animations you call overridePendingTransition() in onNewIntent for the animations to run. https://stackoverflow.com/a/8327091
I tried calling startPostponedEnterTransition() in there but nothing happened.
This is my code to allow for transitions
void allowWindowTransitions(){
Window w = getWindow();
w.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
Code to start activity
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(this, sharedElement, "profile");
startActivity(intent, options.toBundle());
I have tried messing around with setSharedElementReturnTransition & setSharedElementReenterTransition but nothing happened.
Is there a way trigger shared element transition manually to get around this.
回答1:
Not sure about Shared element transitions but you can override onNewIntent method to apply animations when activity comes in foreground.
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.i(TAG, "onNewIntent: ");
overridePendingTransition(R.anim.transition_enter_from_right, R.anim.transition_exit_to_left);
}
Hope this helps!
来源:https://stackoverflow.com/questions/33168580/shared-element-transition-when-reopening-existing-activity-in-stack-reorder-to-f