(I know this question has been asked many times before, but none of the answers that I have read have helped.)
After I rotate my device, my fragment is recreated but the Bundle received in onCreate/onViewStateRestored/etc. is always null. The fragment has a valid ID and retainInstance is set to false.
I am writing to the Bundle provided to the onSaveInstanceState method which is invoked as expected when the device is rotated. After rotation, all the expected lifecycle callbacks are also invoked (onCreate, onActivityCreated, onViewStateRestored, etc.). However, the provided Bundle is null every case.
Everything I have read on this topic would indicate that the fragment should receive the Bundle that was written to in onSaveInstanceState. The only thing I can think of that might be out of the ordinary is that the fragment is inside a navigation graph component. Note that I am not overriding onSaveInstanceState in the activity.
What could cause my fragment's Bundle to be null after rotation?
CodePudding user response:
It turns out that an override of onCreate
in the Activity and was passing null instead of savedInstanceState to super.onCreate
.