Shared Element Transition when reopening existing Activity in stack Reorder To Front

天大地大妈咪最大 提交于 2021-01-27 04:29:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!