Being aware of the fact that this problem was within the android framework and not in my code, i decided to dig around through the android framework source code, setting break points and trying to figure out what was going wrong, finally after a few days of digging, i figured out that the dialog and time picker both are trying to restore the time pickers state but the dialog(parent) actually assigns a blank value to the timepicker hence causing the exception seen. The exception is as follows:
FATAL EXCEPTION: main
java.lang.IndexOutOfBoundsException: setSpan (2 ... 2) ends beyond length 0
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:978)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:549)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:541)
at android.text.Selection.setSelection(Selection.java:74)
at android.widget.EditText.setSelection(EditText.java:97)
at android.widget.NumberPicker$SetSelectionCommand.run(NumberPicker.java:1632)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4028)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
The solution was quite simple at the end when i understood what was causing the problem (it took quite some time to understand) just tell the timepickers parent not to manage the saved state, hence the following to lines were added under the fetching of the control.
LESSON LEARNED : Its not impossible to move mountains.
//Line I mentioned tp = (TimePicker) findViewById(R.id.timePickerComponent); //two lines to add after tp.setSaveFromParentEnabled(false); tp.setSaveEnabled(true);
Well comments and views are welcome, till next time!