I want to implement the shared element transitions in my app for Android Lollipop. After I have read the documents, the SO questions and some posts I decided to give it a go, but now I got a problem.
The scenario is I have two fragment containers (for tablets), just like the normal list/detail design pattern.
I want to do the shared element transitions between the list fragment to detail fragment upon a list item is touched. The enter of the detail fragment is OK, but as soon as I press back button, app crashes with NullPointerException in the transition framework code.
Is the scenario supported by shared element transition?
Here is the code that starts the detail fragment:
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment fragment = DetailFragment.create((int)id);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
View title = view.findViewById(R.id.item_name);
title.setTransitionName("title");
listFragment.setSharedElementReturnTransition(
TransitionInflater.from(this).inflateTransition(R.transition.change_bounds));
listFragment.setExitTransition(
TransitionInflater.from(this).inflateTransition(android.R.transition.explode));
fragment.setSharedElementEnterTransition(
TransitionInflater.from(this).inflateTransition(R.transition.change_bounds));
fragment.setEnterTransition(
TransitionInflater.from(this).inflateTransition(android.R.transition.explode));
ft.addSharedElement(title, "title");
}
else {
ft.setCustomAnimations(R.anim.slide_in_right, 0, 0, R.anim.slide_out_right);
}
ft.replace(R.id.detail_panel, fragment)
.addToBackStack(null)
.commit();
Logcat is here:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.support.v4.app.Fragment.getAllowReturnTransitionOverlap()' on a null object reference
at android.support.v4.app.BackStackRecord.configureTransitions(BackStackRecord.java:1201)
at android.support.v4.app.BackStackRecord.beginTransition(BackStackRecord.java:1029)
at android.support.v4.app.BackStackRecord.popFromBackStack(BackStackRecord.java:883)
at android.support.v4.app.FragmentManagerImpl.popBackStackState(FragmentManager.java:1541)
at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:502)
at android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java:176)
...