Lollipop transitions not working when resuming activity

别等时光非礼了梦想. 提交于 2019-12-10 18:49:31

问题


I have been trying to implement the new Lollipop activity and shared elements transitions during a few days following the steps from Alex Lockwood awesome blog posts. But now I'm facing a bit of a problem.

My application uses a DrawerLayout for navigation, but I can also launch some of the activities when clicking other views and buttons. I have set correctly all the Enter, Reenter, Return and Exit transitions for all the activities as well as calling:

startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(activity, getSharedViewsPairs(activity)).toBundle());

for the shared elements between those activites.

If I launch the activities for the first time, the transitions work up well. My problem comes when I try to launch/resume an activity that has already been called before but that now is paused and lives still on the activity stack. When I try to bring this activity to the foreground, then there is no transition.

I also have to say that I set to all my activities the Intent flag FLAG_ACTIVITY_REORDER_TO_FRONT so that in case they have been already launched before, I don't fresh launch them again. Could this have anything to do with it? Am I missing some method that needs to be called when resuming activities that have been launched previously with transitions?

Code for preparing the activity transitions:

public static void requestTransitionsAnimations(Activity activity) {
    if(MaterialAnimations.isAnimationSupported()){
        Transition transition = TransitionInflater.from(activity).inflateTransition(R.transition.material_transitions);
        activity.getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
        activity.getWindow().setAllowEnterTransitionOverlap(true);
        activity.getWindow().setAllowReturnTransitionOverlap(true);
        activity.getWindow().setEnterTransition(new Explode());
        activity.getWindow().setReenterTransition(new Explode());
        activity.getWindow().setReturnTransition(new Explode());
        activity.getWindow().setExitTransition(new Explode());
        activity.getWindow().setSharedElementsUseOverlay(true);
        activity.getWindow().setSharedElementEnterTransition(transition);
        activity.getWindow().setSharedElementReenterTransition(transition);
        activity.getWindow().setSharedElementExitTransition(transition);
        activity.getWindow().setSharedElementReturnTransition(transition);
    }
}

as

来源:https://stackoverflow.com/questions/31295598/lollipop-transitions-not-working-when-resuming-activity

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