Reputation: 3535
When creating an Activity
to android we must override the onCreate
method and the new method MUST call the super.onCreate
My question is does it need to be the first statement of the new onCreate?
I've a small framework that inject some code in my activities... it was working fine without major problems
then i made some changes to solve minor problems and i switch the call for super.onCreate()
from first to last statement....
now some users are getting
Caused by java.util.ConcurrentModificationException
at androidx.collection.SimpleArrayMap.put(SimpleArrayMap.java:482)
at com.google.android.gms.measurement.internal.zzin.zza(zzin.java:108)
at com.google.android.gms.measurement.internal.zzid.onActivityCreated(zzid.java:11)
at android.app.Application.dispatchActivityCreated(Application.java:221)
at android.app.Activity.onCreate(Activity.java:1071)
at androidx.core.app.ComponentActivity.onCreate(ComponentActivity.java:81)
at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:154)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:312)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:106)
at com.tomatedigital.adinjector.AdsAppCompatActivity.onCreate(AdsAppCompatActivity.java:253)
at com.tomatedigital.giveawaymaster.activity.BaseActivity.onCreate(BaseActivity.java:132)
at com.tomatedigital.giveawaymaster.activity.MainActivity.onCreate(MainActivity.java:623)
at android.app.Activity.performCreate(Activity.java:7258)
at android.app.Activity.performCreate(Activity.java:7249)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1222)
the app is in production over 5k daily users but i wont be able to replicate the error in dev...
does anyone have any idea what might be
Upvotes: 0
Views: 1160
Reputation: 403
Its com.google.firebase:firebase-core
bug. they fixed it in version 17.2.3 see changelog: https://firebase.google.com/support/release-notes/android#analytics_v17-2-3
Upvotes: 0
Reputation: 3535
I just found this an issue in the new firebase-core
and firebase-analytics
apis im importing.
to solve it i need to downgrade
implementation 'com.google.firebase:firebase-core:17.2.0'
for futher information please refer to this. java.util.ConcurrentModificationException in activity onCreate
Upvotes: 1
Reputation: 1892
As you can see here:
And here:
The super
callback has to be called first, to avoid errors due to the incompleteness of the Activity
creation.
Screenshots source: https://developer.android.com/guide/components/activities/activity-lifecycle#java
Upvotes: 1
Reputation: 2737
As per logs and my understanding...
super.onCreate()
call in last is not main reason of crash.
This error is reason of concurrent modification in your HashMap (you have taken) and multiple threads are trying to access and edit in that HashMap.
Because...
HashMap is non synchronized. It is not-thread safe and can't be shared between many threads without proper synchronization code whereas Hashtable is synchronized....
Upvotes: 1