I created a custom DialogPreference that uses two NumberPicker on it to allow the user to select the hour of the day, as well as another custom DialogPreference that allows the user to select the time of day using the TimePicker widget.
As long as the dialogue is not open, and I rotate the screen, everything works as desired. However, if the dialog is open and the screen is rotated, the entire application will crash. I placed breakpoints in the onSaveInstanceState and onRestoreInstanceState and confirmed that everything that is needed to restore DialogPreference is ordered, the onDialogClosed method even hits every time along with all the other custom code that I have custom DialogPreference .
I create the following:
- Minimum SDK: 16
- Target SDK: 20
- Compile SDK: 20
- Build Tools: 20.0.0
I run Android 4.4.3 (KitKat) on a Verizon Galaxy Nexus when this happens.
The following is the value of stacktrace:
java.lang.IndexOutOfBoundsException: setSpan (4 ... 4) ends beyond length 0 at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1016) at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:592) at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:588) at android.text.Selection.setSelection(Selection.java:76) at android.widget.EditText.setSelection(EditText.java:87) at android.widget.NumberPicker$SetSelectionCommand.run(NumberPicker.java:2123) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(NativeStart.java)
source share