0

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

Rafael Lima
  • 3,079
  • 3
  • 41
  • 105
  • please add supporting codes for debugging – Basi Feb 06 '20 at 08:16
  • This is a threading problem - you need to provide some code so that people can help you here. – ligi Feb 06 '20 at 08:16
  • @ligi, i know this is a concurrency problem but MY CODE HAS ZERO THREAD CREATION NOR MANIPULATION and as you can see from the stack trace the exception happens inside one of googles api... my question is related to... "does super.onCreate() turns any important flag that must be the first statement on android activites?" – Rafael Lima Feb 06 '20 at 08:22
  • 1
    no it shouldn't be, because I tried that and not getting crash – NehaK Feb 06 '20 at 08:30

4 Answers4

1

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....

NehaK
  • 2,639
  • 1
  • 15
  • 31
1

As you can see here:

enter image description here

And here:

enter image description 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

Luca Murra
  • 1,848
  • 14
  • 24
  • although your answer is right and the documentation is clear about that, that is not the real cause of my crash. you can check more info in my own answer thanks for helping – Rafael Lima Feb 07 '20 at 07:48
  • I think to understand the cause of your crash, we'd need to see the code – Luca Murra Feb 07 '20 at 16:49
1

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

Rafael Lima
  • 3,079
  • 3
  • 41
  • 105
0

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

Daniel Pína
  • 348
  • 2
  • 7