简体   繁体   中英

savedInstanceState bundle is always null after device rotation

(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?

It turns out that an override of onCreate in the Activity and was passing null instead of savedInstanceState to super.onCreate .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM