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
I think using Pairs as below:
Pair[] pairs = new Pair[1];
pairs[0] = new Pair<View, String>(tvArtifacts, "itemTrans");
ActivityOptions options = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
options = ActivityOptions.makeSceneTransitionAnimation(getActivity(), pairs);
}
Intent i = new Intent(getActivity(), ItemDetailActivity.class);
i.putExtra("item_name", "item 2");
if (options != null) {
startActivity(i, options.toBundle());
} else {
startActivity(i);
}
This worked for me! Thanks..
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
Fragment to Activity is the same as Activity to Activity, Because your Fragment is inside an Activity.
I had the same problem, I couldn't find anything that helps sorry, but maybe you should reconsider why would you need a Fragment to Activity relation when you could work with a Fragment to Fragment or Activity to Activity relation.
I've solved my problem that way changing my code to a Fragment to Fragment relation and there is plenty documentation and examples about that Shared Element Transitions