Android onCreate application class method called multiple times

I overloaded the Application class in my Android application and I use ACRA reporting system. My application looks like ( real source code here ):

public class MyApplication extends Application { @Override public void onCreate() { ACRA.init( this ); /* * Initialize my singletons etc * ... * ... */ super.onCreate(); } } 

And as far as I know, the Application object should be created only once, so the onCreate method should be called only once. The problem is that in my crash reports (from ACRA) I have the following:

 java.lang.RuntimeException: Unable to create service it.evilsocket.myapp.net.N ... java.lang.RuntimeException: Unable to create service it.evilsocket.myapp.net.NetworkMonitorService: java.lang.RuntimeException: Unable to create application it.evilsocket.myapp.MyApplication: **java.lang.IllegalStateException: ACRA#init called more than once** at android.app.ActivityThread.handleCreateService(ActivityThread.java:2283) at android.app.ActivityThread.access$1600(ActivityThread.java:127) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4441) 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:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.RuntimeException: Unable to create application it.evilsocket.myapp.MyApplication: java.lang.IllegalStateException: ACRA#init called more than once at android.app.LoadedApk.makeApplication(LoadedApk.java:495) at android.app.ActivityThread.handleCreateService(ActivityThread.java:2269) ... 10 more Caused by: java.lang.IllegalStateException: ACRA#init called more than once at org.acra.ACRA.init(ACRA.java:118) at it.evilsocket.myapp.MyApplication.onCreate(MyApplication.java:46) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969) at android.app.LoadedApk.makeApplication(LoadedApk.java:492) ... 11 more java.lang.RuntimeException: Unable to create application it.evilsocket.myapp.MyApplication: java.lang.IllegalStateException: ACRA#init called more than once at android.app.LoadedApk.makeApplication(LoadedApk.java:495) at android.app.ActivityThread.handleCreateService(ActivityThread.java:2269) at android.app.ActivityThread.access$1600(ActivityThread.java:127) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4441) 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:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalStateException: ACRA#init called more than once at org.acra.ACRA.init(ACRA.java:118) at it.evilsocket.myapp.MyApplication.onCreate(MyApplication.java:46) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969) at android.app.LoadedApk.makeApplication(LoadedApk.java:492) ... 11 more java.lang.IllegalStateException: ACRA#init called more than once at org.acra.ACRA.init(ACRA.java:118) at it.evilsocket.myapp.MyApplication.onCreate(MyApplication.java:46) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969) at android.app.LoadedApk.makeApplication(LoadedApk.java:492) at android.app.ActivityThread.handleCreateService(ActivityThread.java:2269) at android.app.ActivityThread.access$1600(ActivityThread.java:127) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4441) 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:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) 

So it looks like the onCreate application is being called multiple times, any idea on this?

NOTES:

  • In my xroid manifest, I did NOT using android: process = "string".
  • Yes, I am sure that in my initialization programs I do not accidentally call MyApplication.onCreate.
+11
android acra lifecycle
09 Oct '12 at 23:10
source share
3 answers

If you look at the stack trace, it looks like ACRA.init is makeApplication . I suspect there is some code to check if the application has already been created, and if not, create it and be called by your call to ACRA.init before super.onCreate . As a rule, when overriding onCreate methods (whether Application or Activity ), it is recommended that you call super.onCreate as the first line of your implementation and then super.onCreate your own custom materials. I would give this chance and see if it corrects something.

+7
Oct 09
source share
β€” -

I think you have an additional process in your application. This is why Application.onCreate is called more than once. Browse through your manifest file and try to find an action or service with something like android: process = . This means that the activity / service starts in the second Dalvik virtual machine and that another instance of the application is being created.

+23
May 16 '13 at 9:59
source share

I also see this with ACRA 4.4.0 in the wild.

Perhaps something is as simple as the init method?

 if (mApplication != null) { throw new IllegalStateException("ACRA#init called more than once"); //(return or finish or gracefully exit somehow) } else { mApplication = app; //and then continue with rest of acra init... 

Edit: 12/27/12. As a continuation of this, Kevin seems to have accepted these changes. Details here: https://github.com/ACRA/acra/commit/cda06f5b803a09e9e7cc7dafae2c65c8fa69b861

+6
Nov 25 '12 at 17:18
source share



All Articles