Q:

Race condition between Application onCreate and resources loaded?

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.
public class MyApplication extends Application {

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

This normally works fine, but occasionally when starting my program from eclipse "Run" I get this error:
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)

This id is from my R.java:
public static final int prefkey_updateinterval=0x7f0a0004;

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? 
If that's the case, is it recommended not to read resources in Application onCreate? 
If so, is there a better place to initialize a service when application launches? 

A:

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?

If the same APK file -- no recompile, no reinstall, etc. -- does not consistently generate the error, then it might be some sort of race condition, though that would surprise me.
If the same APK file consistently fails, then this is a more garden-variety resources-out-of-sync-with-the-rest-of-the-code problem, and cleaning the project will clear it up.

is there a better place to initialize a service when application launches?

IMHO, the number of apps that need to "initialize a service when application launches" is extremely low, to the point where I cannot think of a scenario off the cuff where this would be a good plan. That's not to say that you do not have such a scenario, but it's a serious code smell in my book without an explanation.

