3
我的應用程序在Application :: onCreate()方法中做了相當多的初始化工作,我有一個檢查的地方說如果初始化方法被調用兩次,它會通過異常。爲什麼應用程序對象在android上創建兩次?
但是,在某些特定情況下,android中的應用程序對象會被創建兩次。我添加了以下登錄聲明的onCreate()(實例是一個靜態變量)
Log.i(TAG, "Application::ctor, this=" + this + " instance=" + instance + " pid="
+ android.os.Process.myPid());
我有兩個日誌(一般情況下= NULL):
09-20 19:14:42.151 {main} [INFO] [Application] Application::ctor, [email protected] instance=null pid=10741
09-20 19:14:50.116 {main} [INFO] [Application] Application::ctor, [email protected] [email protected] pid=10741
在這種情況下,我回來從onCreate()方法 - 它不會傷害,因爲一切都應該在內存中。然而,從android系統之後立即顯示另一個例外:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.innopath.mobilemd/com.innopath.mobilemd.ui.LauncherActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.view.ContextThemeWrapper.initializeTheme(ContextThemeWrapper.java:100)
at android.view.ContextThemeWrapper.setTheme(ContextThemeWrapper.java:51)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2019)
... 11 more
看起來第二個應用程序創建是由ALARM_MANAGER喚醒引發的。但是,應用程序的第一次創建應該已完成並保存在內存位置?
你在哪裏做你的初始化? –
onDestroy()?沒有什麼 – Shawn
我不確定這會有幫助,但類似的錯誤在這裏描述:http://code.google.com/p/android/issues/detail?id=56296 –