Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I also ran into this problem. Jon Skeet's suspicions were correct, the problem is that the time zones are being loaded really inefficiently, opening a jar file and then reading the manifest to try to get this information.</p> <p>However, simply calling <code>DateTimeZone.setProvider([custom provider instance ...])</code> is not sufficient because, for reasons that don't make sense to me, DateTimeZone has a static initializer where it calls <code>getDefaultProvider()</code>.</p> <p>To be completely safe, you can override this default by setting this system property before you ever call anything in the joda. </p> <p>In your activity, for example, add this:</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { System.setProperty("org.joda.time.DateTimeZone.Provider", "com.your.package.FastDateTimeZoneProvider"); } </code></pre> <p>Then all you have to do is define <code>FastDateTimeZoneProvider</code>. I wrote the following:</p> <pre><code>package com.your.package; public class FastDateTimeZoneProvider implements Provider { public static final Set&lt;String&gt; AVAILABLE_IDS = new HashSet&lt;String&gt;(); static { AVAILABLE_IDS.addAll(Arrays.asList(TimeZone.getAvailableIDs())); } public DateTimeZone getZone(String id) { if (id == null) { return DateTimeZone.UTC; } TimeZone tz = TimeZone.getTimeZone(id); if (tz == null) { return DateTimeZone.UTC; } int rawOffset = tz.getRawOffset(); //sub-optimal. could be improved to only create a new Date every few minutes if (tz.inDaylightTime(new Date())) { rawOffset += tz.getDSTSavings(); } return DateTimeZone.forOffsetMillis(rawOffset); } public Set getAvailableIDs() { return AVAILABLE_IDS; } } </code></pre> <p>I've tested this and it appears to work on Android SDK 2.1+ with joda version 1.6.2. It can of course be optimized further, but while profiling my app (<a href="https://market.android.com/details?id=com.mogwee">mogwee</a>), this decreased the DateTimeZone initialize time from ~500ms to ~18ms.</p> <p>If you are using proguard to build your app, you'll have to add this line to proguard.cfg because Joda expects the class name to be exactly as you specify:</p> <pre><code>-keep class com.your.package.FastDateTimeZoneProvider </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload