One of my Android apps uses a custom Application class to perform some global initialization. This done in the onCreate()
method:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
someCustomInit();
}
}
This works fine, but now I have discovers a crash log in the Developer Console which indicated that MyApplication.onCreate()
did not run / has not completed at the time the crash happened: The code crashed because some initialization that is performed MyApplication.onCreate()
was not complete.
How is this possible? I assumed that MyApplication.onCreate()
would run before all other code? Isn't that correct?
Is it save to move someCustomInit();
to the constructor of MyApplication
instead? No other code should run before the application object has been created, correct?
Or are there any side effects from using the constructor instead of onCreate()
?