-
Notifications
You must be signed in to change notification settings - Fork 4k
🐛 [firebase_messaging] Inconsistent behavior with background message handler callback on Android. #4017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't see this file in documentation which you have used - FirebaseCloudMessagingPluginRegistrant.kt . Code for MainActivity.kt - package com.example.yourpackagename
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
} Code for Application.kt - package com.example.yourpackagename
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
override fun registerWith(registry: PluginRegistry?) {
io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
} Apart from this, you also need to do some changes in the AndroidManifest.xml and app level build.gradle. Assuming that you have done those changes already, I would suggest you to try these changes given above. Also I would like to know what do you want to do in the background message handler, because even though the background message handler is getting fired consistently in my application but its of no use because I am unable to do anything inside it except from printing some thing in the console. Seems that the background message handler runs as an isolate - #3520 , I wanted to use Firestore in background but it isn't possible it seems, because FirebaseApp needs to be initialized which is itself not possible in an isolate. Therefore, I tried to add what I wanted to do in sharedPreferences, so that I could perform those tasks when the app starts in the foreground, but unfortunately, I am unable to access sharedPreferences in the background message handler as well. Seems like the backgroundMessageHandler is useless for now.. |
Hi @firatcetiner Paylaod
logs when each payload is sent
|
@TahaTesser Update: I changed my code to match the code above but the same issue appears even in the foreground message handler method, I can't reach any payload. This is very strange. |
There is a 8.0 dev release out with major reworks to background handling if you want to give the release a try. |
@Ehesp Thanks for pointing that out. By 8.0 dev I'm assuming you are referring firebase_messaging (dev) because I already tried that and nothing change. Dependency
|
@firatcetiner is this issue happening on emulator or physical device? |
@mdalihusain All tests done on physical devices. I have used Xiaomi Redmi Note 8 Pro (Android 10), Xiaomi Mi 6 (Android 9). Why should I worry about the manufacturer? |
It's fine, mine is also Xiaomi Redmi Note 8 Pro (Android 10), and everything is working absolutely fine Only two other reasons I can think because of which the issue is occurring -
|
@mdalihusain Thanks for your help. Here are the files: AndroidManifest.xml
build.gradle (module)
builld.gradle (project)
What's the point of trying this plugin on a new project? I mean we always use other packages/plugins in our projects and it is almost impossible to determine which plugin cause incompatibilities with Firebase Messaging, or vice versa. |
The build.gradle and AndroidManifest files seem to be alright... The point with creating a new application is to make sure that another plugin is causing this issue or the problem is with Firebase messaging itself . |
Well if that is the case it means I have to manually check every other plugin separately to see the incompatibilities, which is not ideal for me since I'm using tons of different packages/plugins. Anyway, I will try creating a new project using only Firebase Messaging. |
We meant |
I confirm that firebase_messaging 8.0.0-dev.4 resolves this issue and I'm going to close it, it would be good to have some ideas about when this new rework land on the stable channel. Thank you all for your help |
@firatcetiner 1-2 weeks - providing no major issues reported whilst on dev channel. |
What happened?
Firebase Cloud Messaging plugin's background message handler doesn't always work correctly. The message raised from Flutter debug console is
W/FirebaseInstanceId(17720): Service took too long to process intent: com.google.android.c2dm.intent.RECEIVE App may get closed.
. I get this "error" most of the times. See related issue #2181 and pull request #1774 (which claims to solve this issue). I was doing some sqlite operations with moor_flutter on that method and I completely ignored them for now. Right now the handler method is like this:And it doesn't event print 'message received'.
Steps to reproduce
Steps to reproduce the behavior:
firebase_messaging: 7.0.3
,Plugin Registry
Application.kt
FirebaseCloudMessagingPluginRegistrant.kt
flutter doctor -v
Flutter dependencies
The text was updated successfully, but these errors were encountered: