Android Question Firebase messaging is crashing (API >= 26 (Oreo))

johndb

Active Member
Licensed User
Longtime User
I am updating my apps to the latest android OS and am having difficulty with implementing Firebase messaging using the latest Android API. I have searched the forum and had not found anything discussing this issue. I may have missed a previous discussion. Sorry if this has already been discussed.

The issue is that the Firebase messaging service will crash if the app is not foreground or isn't in the "recent" list. The Firebase messaging works fine running under pre-Oreo even when the app is not foreground and not in the "recent" list.

I believe that it may be related to the recent os changes described here: https://developer.android.com/about/versions/oreo/background.html.

Crash report:
Exception java.lang.IllegalStateException: Not allowed to start service Intent { act=b4a_firebasemessaging cmp=com.scsoftstudios.edacec/.firebasemessaging (has extras) }: app is in background uid UidRecord{d6ef069 u0a304 RCVR idle change:uncached procs:1 seq(0,0,0)}
android.app.ContextImpl.startServiceCommon (ContextImpl.java:1521)
android.app.ContextImpl.startService (ContextImpl.java:1477)
android.content.ContextWrapper.startService (ContextWrapper.java:650)
anywheresoftware.b4a.objects.FirebaseNotificationsService.onMessageReceived (FirebaseNotificationsService.java:54)
com.google.firebase.messaging.FirebaseMessagingService.handleIntent ()
com.google.firebase.iid.zzg.run ()
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
java.lang.Thread.run (Thread.java:764)

Has anybody discovered a workaround for this issue where Firebase messaging works properly with Oreo devices whether the app is not in the foreground nor in the "recent" list?

Thank you for your help.

John
 

johndb

Active Member
Licensed User
Longtime User
Don't set targetSdkVersion to 26 for now. See the background limitation note: https://www.b4x.com/android/forum/threads/android-jar-targetsdkversion-minsdkversion.87610/#content

It will be addressed in the next update of B4A.
Thank you @Erel. I downgraded my apps to SDK 25 and Firebase messaging is working properly now on all my test bench devices including devices currently running OS 8.1 (SDK 27). I have updated all my apps to include many of the requirements such as "runtime permissions" and "File Provider" and they are working well when I target the apps to SDK 27. Regardless, those upgrades also work with SDK 25.
My only issue at the present time are services such as Firebase Messaging. I'm looking forward to future B4A updates that will address these issues. I'm planning to publish in the fall of this year so I hope that this is resolved. Thank you again.
 
Last edited:
Upvote 0
Top