After rotation Month calendar shows Jan 1900
After an orientation change the date of the Month calendar is set to January 1900 (the selected date is still the right one):


I'm starting the dialog this way:
// From the ViewModel class
public void onDateClicked() {
Calendar cal = Calendar.getInstance();
cal.setTime(exam.getDate());
DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(
this,
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH)
);
dataListener.showDialogFragment(datePickerDialog, DatePickerDialog.class.getName());
}
// Activity class
@Override
public void showDialogFragment(DialogFragment dialogFragment, String tag) {
dialogFragment.show(getFragmentManager(), tag);
dialogFragmentTagList.add(tag);
}
Reproducible on AVD API 24 and Nexus 6P Android 7.0.
This feels like a Nougat specific issue. The state is properly restored, but it's not scrolling the selection into view. I think I know how to fix this.
any solution of this bug.
I had a look at this and the potential solution I was thinking of, is actually already there. In the mean time I have a device that runs nougat and I can't reproduce this on the master branch.
I did change the ListView to a RecyclerView there, so maybe that also fixed this. Can you try master and report back?
I have samsung s7 with android 7.0 yesterday I have download your master project and import to AndroidStudio, I send you Logcat : start when pick date, and start rotate begin from time 04-20 16:02:47.895
04-20 16:02:43.733 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@e1184d[MainActivity]: ViewPostImeInputStage processPointer 0 04-20 16:02:43.805 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@e1184d[MainActivity]: ViewPostImeInputStage processPointer 1 04-20 16:02:43.844 11082-11082/com.wdullaer.materialdatetimepicker.sample D/AbsListView: Get MotionRecognitionManager 04-20 16:02:43.846 11082-11082/com.wdullaer.materialdatetimepicker.sample D/MotionRecognitionManager: mSContextService = com.samsung.android.hardware.context.ISemContextService$Stub$Proxy@bbe5550 04-20 16:02:43.848 11082-11082/com.wdullaer.materialdatetimepicker.sample D/MotionRecognitionManager: motionService = com.samsung.android.gesture.IMotionRecognitionService$Stub$Proxy@9e8e349 04-20 16:02:43.848 11082-11082/com.wdullaer.materialdatetimepicker.sample D/MotionRecognitionManager: motionService = com.samsung.android.gesture.IMotionRecognitionService$Stub$Proxy@9e8e349 04-20 16:02:43.850 11082-11087/com.wdullaer.materialdatetimepicker.sample I/art: Do full code cache collection, code=114KB, data=122KB 04-20 16:02:43.853 11082-11087/com.wdullaer.materialdatetimepicker.sample I/art: After code cache collection, code=114KB, data=96KB 04-20 16:02:43.885 11082-11082/com.wdullaer.materialdatetimepicker.sample D/InputTransport: Input channel constructed: fd=86 04-20 16:02:43.885 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@f24b281[MainActivity]: setView = DecorView@1c97f26[] touchMode=true 04-20 16:02:43.952 11082-11103/com.wdullaer.materialdatetimepicker.sample D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1098x1872]-format:1 04-20 16:02:43.966 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@f24b281[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 04-20 16:02:43.967 11082-11082/com.wdullaer.materialdatetimepicker.sample I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus 04-20 16:02:43.970 11082-11082/com.wdullaer.materialdatetimepicker.sample D/InputTransport: Input channel constructed: fd=89 04-20 16:02:43.970 11082-11082/com.wdullaer.materialdatetimepicker.sample D/InputTransport: Input channel destroyed: fd=84 04-20 16:02:44.007 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@f24b281[MainActivity]: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1 04-20 16:02:44.082 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@e1184d[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 0 04-20 16:02:47.895 11082-11082/com.wdullaer.materialdatetimepicker.sample D/AbsListView: Get MotionRecognitionManager 04-20 16:02:47.979 11082-11103/com.wdullaer.materialdatetimepicker.sample D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1908x1200]-format:1 04-20 16:02:48.002 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@f24b281[MainActivity]: dispatchDetachedFromWindow 04-20 16:02:48.008 11082-11082/com.wdullaer.materialdatetimepicker.sample D/InputTransport: Input channel destroyed: fd=86 04-20 16:02:48.010 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@e1184d[MainActivity]: dispatchDetachedFromWindow 04-20 16:02:48.014 11082-11082/com.wdullaer.materialdatetimepicker.sample D/InputTransport: Input channel destroyed: fd=81 04-20 16:02:48.079 11082-11082/com.wdullaer.materialdatetimepicker.sample D/AbsListView: Get MotionRecognitionManager 04-20 16:02:48.080 11082-11082/com.wdullaer.materialdatetimepicker.sample D/MotionRecognitionManager: mSContextService = com.samsung.android.hardware.context.ISemContextService$Stub$Proxy@4bfb6e5 04-20 16:02:48.081 11082-11082/com.wdullaer.materialdatetimepicker.sample D/MotionRecognitionManager: motionService = com.samsung.android.gesture.IMotionRecognitionService$Stub$Proxy@978d5ba 04-20 16:02:48.081 11082-11082/com.wdullaer.materialdatetimepicker.sample D/MotionRecognitionManager: motionService = com.samsung.android.gesture.IMotionRecognitionService$Stub$Proxy@978d5ba 04-20 16:02:48.094 11082-11082/com.wdullaer.materialdatetimepicker.sample D/InputTransport: Input channel constructed: fd=81 04-20 16:02:48.094 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@f706212[MainActivity]: setView = DecorView@ca76de3[] touchMode=true 04-20 16:02:48.102 11082-11082/com.wdullaer.materialdatetimepicker.sample D/InputTransport: Input channel constructed: fd=82 04-20 16:02:48.102 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@75723e0[MainActivity]: setView = DecorView@c48b699[MainActivity] touchMode=true 04-20 16:02:48.130 11082-11103/com.wdullaer.materialdatetimepicker.sample D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1908x1200]-format:1 04-20 16:02:48.151 11082-11103/com.wdullaer.materialdatetimepicker.sample D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1920x1080]-format:1 04-20 16:02:48.152 11082-11082/com.wdullaer.materialdatetimepicker.sample E/ViewRootImpl: sendUserActionEvent() mView == null 04-20 16:02:48.153 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@f706212[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 04-20 16:02:48.153 11082-11082/com.wdullaer.materialdatetimepicker.sample I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus 04-20 16:02:48.154 11082-11082/com.wdullaer.materialdatetimepicker.sample D/InputTransport: Input channel constructed: fd=85 04-20 16:02:48.154 11082-11082/com.wdullaer.materialdatetimepicker.sample D/InputTransport: Input channel destroyed: fd=89 04-20 16:02:48.185 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@f706212[MainActivity]: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=2 04-20 16:02:48.186 11082-11082/com.wdullaer.materialdatetimepicker.sample D/ViewRootImpl@75723e0[MainActivity]: MSG_RESIZED_REPORT: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=2
04-20 16:02:43.850 11082-11087/com.wdullaer.materialdatetimepicker.sample I/art: Do full code cache collection, code=114KB, data=122KB 04-20 16:02:43.853 11082-11087/com.wdullaer.materialdatetimepicker.sample I/art: After code cache collection, code=114KB, data=96KB 04-20 16:02:43.967 11082-11082/com.wdullaer.materialdatetimepicker.sample I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus 04-20 16:02:48.152 11082-11082/com.wdullaer.materialdatetimepicker.sample E/ViewRootImpl: sendUserActionEvent() mView == null 04-20 16:02:48.153 11082-11082/com.wdullaer.materialdatetimepicker.sample I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus 04-20 16:02:52.992 11082-11082/com.wdullaer.materialdatetimepicker.sample W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection
and
04-20 16:02:48.152 11082-11082/com.wdullaer.materialdatetimepicker.sample E/ViewRootImpl: sendUserActionEvent() mView == null 04-20 16:02:52.992 11082-11082/com.wdullaer.materialdatetimepicker.sample W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection
and ERROR: 04-20 16:02:48.152 11082-11082/com.wdullaer.materialdatetimepicker.sample E/ViewRootImpl: sendUserActionEvent() mView == null
Has there been any solution to this bug? I'm still having this issue as of version 4.1.0.
Like I mentioned, I am not able to reproduce this here locally. There is code to restore the state.
Are you experiencing this on all devices?
Which features of the pickers are you using?
Looks like this is only happening on my Moto X Pure test device. Any other device I try works just fine.
Can you try the sample app?
Maybe set a breakpoint at line 323 and 456 in the onCreateViewView() method of DatePickerDialog to see what the state looks like.
Does this also happen with the Timepicker?

Here are some screenshots of the states. I can also confirm this does NOT happen with time picker.
I think the problem in 2 commits
- bc9cf01d3f603bdf38d9c9981f2e1463e16487c1 The guy added to sample activity
configChanges()andonConfigurationChanges()toDatePickerDialog.javaandTimePickerDialog.java - 2190c958db1837f74135434d7c9465529770359a Then he removed configChanges, but still using onConfigurationChanges with really strange part As example looking into
DatePickerDialog.java
@Override
public void onConfigurationChanged(final Configuration newConfig) {
super.onConfigurationChanged(newConfig);
ViewGroup viewGroup = (ViewGroup) getView();
if (viewGroup != null) {
viewGroup.removeAllViewsInLayout();
//null instead of bundle with state, because of this we loosing current date!
View view = onCreateView(getActivity().getLayoutInflater(), viewGroup, null);
viewGroup.addView(view);
}
}
We didn't need any onConfigurationChanged() because onSaveInstanceState() covered all cases for the state restorarion.
The bug is producing on android 7.0 only, on higher versions onConfigurationChanged() not called without configChanges.
This error is producing memmory leak and canary from sample said about that.