I got error when detaching (removing) a Fragment
from my FragmentManager
.
Detaching:
public void onFragmentDetached(String tag) {
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentByTag(tag);
if (fragment != null) {
fragmentManager
.beginTransaction()
.disallowAddToBackStack()
.setCustomAnimations(R.anim.slide_left, R.anim.slide_right)
.remove(fragment)
.commitNow();
unlockDrawer();
}
}
Attaching:
getSupportFragmentManager()
.beginTransaction()
.disallowAddToBackStack()
.setCustomAnimations(R.anim.slide_left, R.anim.slide_right)
.replace(R.id.mainRootView, settingsFragment, SettingsFragment.TAG)
.commit();
Here is my error:
E/FragmentManager: No field with the name mListener is found in Animation class
java.lang.NoSuchFieldException: No field mListener in class Landroid/view/animation/Animation; (declaration of 'android.view.animation.Animation' appears in /system/framework/framework.jar!classes3.dex)
at java.lang.Class.getDeclaredField(Native Method)
at androidx.fragment.app.FragmentManagerImpl.getAnimationListener(FragmentManager.java:1301)
at androidx.fragment.app.FragmentManagerImpl.animateRemoveFragment(FragmentManager.java:1638)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1548)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:797)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243)
at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:648)
at com.fearefull.todoreminder.ui.main.MainActivity.onFragmentDetached(MainActivity.java:148)
at com.fearefull.todoreminder.ui.settings.SettingsFragment.goBack(SettingsFragment.java:71)
at com.fearefull.todoreminder.ui.settings.SettingsViewModel.onNavigationBackClick(SettingsViewModel.java:23)
at com.fearefull.todoreminder.databinding.FragmentSettingsBindingImpl._internalCallbackOnClick(FragmentSettingsBindingImpl.java:188)
at com.fearefull.todoreminder.generated.callback.OnClickListener.onClick(OnClickListener.java:11)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3400(View.java:801)
at android.view.View$PerformClick.run(View.java:27301)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7319)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934)
I'm using SDK version 29, How can I fix this?
to simply put, just add below line to your build.gradle(:app), implementation "androidx.fragment:fragment:1.3.3"
This bug has been fixed in newer versions of androidx.fragment
as mentioned in bug report someone made due to existing issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With