jjobes / SlideDateTimePicker

A combined DatePicker and TimePicker in a DialogFragment for Android
Apache License 2.0
836 stars 235 forks source link

Changed calls to getTargetFragment() to getParentFragment() to solve crashes on rotation #46

Open irenenaya opened 7 years ago

irenenaya commented 7 years ago

The app would crash on rotation or backgrounding. That is due to the target fragment not being found when the hosting fragment is recreated. According to the discussions here: https://issuetracker.google.com/issues/36969568 and in many other places, the issue mainly is caused by the calls to setTargetFragment() and getTargetFragment(). The SlideDateTimeDialogFragment class calls for the ChildFragmentManager (as opposed to a FragmentManager) when instantiating the ViewPagerAdapter. Therefore, the DateFragment and TimeFragment should have the Dialog as parent. The issue is solved by changing the calls to getTargetFragment() in the callbacks from TimeFragment and DateFragment to be calls to getParentFragment(), and by removing the calls to setTargetFragment() in the getItem() method of the SlideDateTimeDialogFragment class.

luyuan11233 commented 4 years ago

you are right,thank you

lunay0ung commented 4 years ago

thanks for your help!

Kwenziwa commented 2 years ago

Thank you soo much this worked for me.