I am using a TimePicker under API 1.5 and when the orientation is changed on my device (a stock G1 running 1.6 - though NOT on the 1.5/1.6 emulator), the hour field goes blank. It still remembers the hour, it just doesn't show it. Is there any workaround for this?
The same problem was described by someone else here:
http://groups.google.com/group/android-beginners/browse_thread/thread/b4288004021b876/de5899a2bb291ab5
Nothing helpful was forthcoming - can StackOverflow do better?
Simply move invoking of methods TimePicker.setCurrentHour and TimePicker.setCurrentMinute to onResume method of your Activity.
As mentioned, overriding the onResume() method will sort this issue.
@Override
public void onResume() {
super.onResume();
TimePicker tmp = (TimePicker) this.findViewById(R.id.yourTimePicker);
tmp.setCurrentHour(7); // This will also set on rotate
}
Take a look at this: http://code.google.com/p/android/issues/detail?id=22824 No matter what you do you won't be able to fix the issue without destroying the Activity and recreating it when the rotate occurs. In order to not enter an endless loop simple check to see if the savedInstanceState != null in the onCreate. Something like this will work:
if (savedInstanceState!=null){
Intent myIntent =
new Intent(getApplicationContext(), CurrentClassName.class);
startActivityForResult(myIntent, 0);
finish();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With