how to Shared element transition from a fragment to an activity

user3740778 picture user3740778 · Jul 26, 2016 · Viewed 8.3k times · Source

I have three fragments inside a ViewPager in an activity, I want to achieve shared element transition from one of the fragments to another activity. The transition is from a recycler view which is inside a fragment which is inside a viewpager which is inside an Activity Activity->ViewPager->Fragment->Recyclerview

I have searched each every places internet but there are info only about shared element transition from one fragment to another and one activity to another. There is no content about transition from fragment to activity

holder.poster.setTransitionName("posterX");
            ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) con,holder.poster,holder.poster.getTransitionName());
            Log.e("Animation", "Success");
            //startActivity((Activity) con,intent,options.toBundle());
            c.startActivity(intent,options.toBundle());

On using the above code the second activity is launched but nothing is visible, For example the second activity contains a FAB which when clicked youtube is launched. I know where the FAB is so when i click blindly, youtube launched correctly but nothing is visible in second activity

D/ViewRootImpl: changeCanvasOpacity: opaque=true

Its one of the logcats. I think this must be the problem!!

Answer

Koma Yip picture Koma Yip · Dec 29, 2017

I finally found the answer, the startActivity calling method is different. You have to call

startActivityFromFragment(fragment, intent, req_code, options.toBundle());

from the AppCompactActivity