Race condition between Application onCreate and resources loaded?
<p>I have the following application class for my app. When the application starts, I want to get some settings from preferences and start a background service.</p>

<pre><code>public class MyApplication extends Application {

    public void onCreate() {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
            String key = getResources().getString(R.string.prefkey_updateinterval);
            ...
    }
</code></pre>

<p>This normally works fine, but occasionally when starting my program from eclipse "Run" I get this error:</p>

<pre><code>10-10 08:25:47.016: E/AndroidRuntime(26402): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f0a0004
10-10 08:25:47.016: E/AndroidRuntime(26402):    at android.content.res.Resources.getText(Resources.java:216)
10-10 08:25:47.016: E/AndroidRuntime(26402):    at android.content.res.Resources.getString(Resources.java:269)
10-10 08:25:47.016: E/AndroidRuntime(26402):    at com.karwosts.MyApp.PortfolioStore.onCreate(PortfolioStore.java:40)
10-10 08:25:47.016: E/AndroidRuntime(26402):    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
10-10 08:25:47.016: E/AndroidRuntime(26402):    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3395)
</code></pre>

<p>This id is from my R.java:</p>

<pre><code>public static final int prefkey_updateinterval=0x7f0a0004;
</code></pre>

<p>Since this works fine most of the time, I have to assume that there is some kind of race condition between onCreate and the resources being loaded? </p>

<p>If that's the case, is it recommended not to read resources in Application onCreate? </p>

<p>If so, is there a better place to initialize a service when application launches? </p>
