Skip to content

onNewIntent override crashes sometimes when calling startService #543

@igor84

Description

@igor84

Please fill in the following fields:

Unity editor version: 2019.1.14f1
Firebase Unity SDK version: 5.7.0
Firebase plugins in use (Auth, Database, etc.): Crashlytics, Messaging
Additional SDKs you are using (Facebook, AdMob, etc.): Facebook
Platform you are using the Unity editor on (Mac, Windows, or Linux): Windows
Platform you are targeting (iOS, Android, and/or desktop): Android
Scripting Runtime (Mono, and/or IL2CPP): IL2CPP

Please describe the issue here:

We followed instructions for configuring a custom entry point Activity at https://firebase.google.com/docs/cloud-messaging/unity/client and added this code to our Activity:

protected void onNewIntent(Intent intent) {
  Intent message = new Intent(this, MessageForwardingService.class);
  message.setAction(MessageForwardingService.ACTION_REMOTE_INTENT);
  message.putExtras(intent);
  message.setData(intent.getData());
  startService(message); // This is line 77 from the stacktrace bellow
}

We noticed on Crashlytics a number of crashes happening with following message and stack trace:
Caused by java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE cmp=com.nordeus.heroic/com.google.firebase.messaging.MessageForwardingService }: app is in background uid UidRecord{7abca70 u0a14 LAST bg:+2m48s495ms idle change:idle procs:1 seq(1760,1760,1760)}
at android.app.ContextImpl.startServiceCommon + 1720(ContextImpl.java:1720)
at android.app.ContextImpl.startService + 1675(ContextImpl.java:1675)
at android.content.ContextWrapper.startService + 669(ContextWrapper.java:669)
at eu.nordeus.common.MainPlayerNativeActivity.onNewIntent + 77(MainPlayerNativeActivity.java:77)
at android.app.Activity.performNewIntent + 8080(Activity.java:8080)
at android.app.Instrumentation.callActivityOnNewIntent + 1413(Instrumentation.java:1413)
at android.app.Instrumentation.callActivityOnNewIntent + 1426(Instrumentation.java:1426)
at android.app.ActivityThread.deliverNewIntents + 4002(ActivityThread.java:4002)
at android.app.ActivityThread.handleNewIntent + 4014(ActivityThread.java:4014)
at android.app.servertransaction.NewIntentItem.execute + 53(NewIntentItem.java:53)
at android.app.servertransaction.TransactionExecutor.executeCallbacks + 149(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute + 103(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage + 2373(ActivityThread.java:2373)
at android.os.Handler.dispatchMessage + 107(Handler.java:107)
at android.os.Looper.loop + 213(Looper.java:213)
at android.app.ActivityThread.main + 8147(ActivityThread.java:8147)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 513(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main + 1100(ZygoteInit.java:1100)

Please answer the following, if applicable:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)?

We couldn't reproduce this issue, we only observed it happening in the wild.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions