Closed Scorpionstvo closed 1 year ago
It is expected behaviour of the library. Working with a ViewBinding is allowed only between onViewCreated and onDestroyView. The best place for keeping text is ViewModel or keep it as separate property in Fragment
From Fragment A on button click I go to Fragment B adding to the stack so I can return to Fragment A on back button. In Fragment A, I'm saving the state with onSaveInstanceState. When I am in Fragment B and rotate the screen, the app crashes with an error: IllegalStateException: Fragment is not attached to Activity. this is how I load fragments in Activity:
Fragment A:
StackTrace:
java.lang.IllegalStateException: Fragment's view can't be accessed. Fragment isn't added at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.getValue(ViewBindingProperty.kt:87) at by.kirich1409.viewbindingdelegate.FragmentViewBindingProperty.getValue(FragmentViewBindings.kt:63) at by.kirich1409.viewbindingdelegate.FragmentViewBindingProperty.getValue(FragmentViewBindings.kt:52) at com.xabber.presentation.application.fragments.chatlist.add.NewChatFragment.getBinding(NewChatFragment.kt:12) at com.xabber.presentation.application.fragments.chatlist.add.NewChatFragment.onSaveInstanceState(NewChatFragment.kt:44) at androidx.fragment.app.Fragment.performSaveInstanceState(Fragment.java:3288) at androidx.fragment.app.FragmentStateManager.saveBasicState(FragmentStateManager.java:681) at androidx.fragment.app.FragmentStateManager.saveState(FragmentStateManager.java:647) at androidx.fragment.app.FragmentStore.saveActiveFragments(FragmentStore.java:214) at androidx.fragment.app.FragmentManager.saveAllStateInternal(FragmentManager.java:2380) at androidx.fragment.app.FragmentManager.lambda$attachController$4$androidx-fragment-app-FragmentManager(FragmentManager.java:2658) at androidx.fragment.app.FragmentManager$$ExternalSyntheticLambda4.saveState(Unknown Source:2) at androidx.savedstate.SavedStateRegistry.performSave(SavedStateRegistry.kt:247) at androidx.savedstate.SavedStateRegistryController.performSave(SavedStateRegistryController.kt:81) at androidx.activity.ComponentActivity.onSaveInstanceState(ComponentActivity.java:368) at android.app.Activity.performSaveInstanceState(Activity.java:2088) at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1486) at android.app.ActivityThread.callActivityOnSaveInstanceState(ActivityThread.java:5419) at android.app.ActivityThread.callActivityOnStop(ActivityThread.java:4732) at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5367) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5302) at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2047) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:224)