Can general element transitions work for fragments in different containers?

I want to implement common element transitions in my Android app Lollipop. After I read the docs, SO questions and some messages I decided to give him, but now I have a problem.

Scenario: I have two containers for fragments (for tablets), as well as the usual list / detail design template.

I want to make transitions of shared elements between a list fragment and a detail fragment on a list element. Entering the part fragment is fine, but as soon as I click the button, the application crashes with a NullPointerException in the transition code.

Is the script supported by a common element transition?

Here is the code that starts the fragment of the part:

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) ... 
+6
source share

Source: https://habr.com/ru/post/980111/


All Articles