Android Application class method onCreate being called multiple times

筅森魡賤 提交于 2019-11-27 20:14:47

If you look at the stack trace, it looks like ACRA.init is calling makeApplication. I suspect that there's some sort of code to check if the application has been created already and if not, create it and that it is caused by your calling ACRA.init before super.onCreate. Generally when overriding onCreate methods (whether Application or Activity) it's recommended to call super.onCreate as the first line of your implementation and do your custom stuff afterwards. I'd give that a shot and see if it fixes things.

I think that you have additional process in your application. That is why Application.onCreate is called more than once. Look into your manifest file and try to find the activity or service with something like android:process= . This means that activity/service is starting in second Dalvik VM, and that's why another application instance is created.

I'm also seeing this with ACRA 4.4.0 in the wild.

Perhaps something as simple as this under 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 follow up to this, it looks like Kevin has adopted these changes. Details are here: https://github.com/ACRA/acra/commit/cda06f5b803a09e9e7cc7dafae2c65c8fa69b861

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!