Why DateTimeZone.getDefault() does not get updated when Zone in Android is changed

Viewed 1133

I reviewed many questions related to TimeZones on Stackoverflow, but I could not find the one to the problem I am struggling with:

  • Why doesn't Joda's DateTimeZone.getDefault() return updated timezone on TZ change (after resuming an application?). TimeZone.getDefault() seems to be working just fine.
  • Should I use DateTimeZone.forTimeZone(TimeZone.getDefault()) to get up to date Joda's DateTimeZone object?

Here is how to replicate:

  1. Start app that prints both DateTimeZone.getDefault() and TimeZone.getDefault():

09-15 16:46:59.512 14961-14961/com.example.android.whatever D/TimeZone: DateTimeZone.getDefault()=Europe/London; TimeZone.getDefault()=libcore.util.ZoneInfo[id="Europe/London",...]

  1. Go to settings -> change Timezone to PDT.
  2. Go back to Application that prints stuff (e.g. in onResume()):

09-15 08:49:24.727 14961-14961/com.example.android.whatever D/TimeZone: DateTimeZone.getDefault()=Europe/London; TimeZone.getDefault()libcore.util.ZoneInfo[id="America/Los_Angeles",...]

  1. At this stage I can be rotating the App. The DateTimeZone.getDefault() will be stuck.
  2. Only after application onRestart - the value will be correct.

Why is it so?

2 Answers
Related