-
Notifications
You must be signed in to change notification settings - Fork 286
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
Notifications delayed when app not running, on Android #342
Comments
This completes the core functionality of showing notifications on Android, zulip#320. Sadly this does not work very well if the app isn't running at all: e.g., if you terminate the app by swiping it away in the app switcher. In that case the notification can be quite a bit delayed. But fixing that seems likely to require some deeper debugging, and getting our hands into Java or Kotlin code for I think the first time in zulip-flutter. So we'll deal with that as a followup issue, zulip#342. Details there. Fixes: zulip#320
This completes the core functionality of showing notifications on Android, #320. Sadly this does not work very well if the app isn't running at all: e.g., if you terminate the app by swiping it away in the app switcher. In that case the notification can be quite a bit delayed. But fixing that seems likely to require some deeper debugging, and getting our hands into Java or Kotlin code for I think the first time in zulip-flutter. So we'll deal with that as a followup issue, #342. Details there. Fixes: #320
It looks like the symptoms of this may vary between devices. My observations above were on my Pixel 5 running Android 13. @chrisbobbe reports at #352 (review) :
So that's something to bear in mind when investigating. One thing I wonder is if the difference is in the app switcher UI — if maybe the one in Samsung's Android 9 leaves the app still in the background, in a way that the one in Google/Pixel's Android 13 doesn't. |
Hello, Just to let you know that I managed to get the notifications working by adding the following annotation before the function: Another issue I am facing right now is, there is no sound during the notification and the notification itself disappears right after it shows up on the screen. @pragma('vm:entry-point')
static Future<void> _onBackgroundMessage(FirebaseRemoteMessage message) async {
// This callback will run in a separate isolate from the rest of the app.
// See docs:
// https://firebase.flutter.dev/docs/messaging/usage/#background-messages
_initBackgroundIsolate();
assert(debugLog("notif message in background: ${message.data}"));
_onRemoteMessage(message);
} The file I edited is notifications.dart file. I got this tip from another developer who posted under firebase project. |
Interesting, thanks. If I understand you correctly, the change was that you added this line: @pragma('vm:entry-point') It makes sense that that could be needed, so that's a good thing to try.
Let's discuss separate issues in separate threads. 🙂 I'd be glad to investigate these either in a new issue thread here on GitHub, or in a thread in |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
A user reported what's probably this issue: https://chat.zulip.org/#narrow/stream/48-mobile/topic/notifications.20on.20zulip.20and.20zulip.20beta/near/1735721 |
I tried the In particular one observation is that the issue reproduces for me even in debug mode, not only in release mode. That pragma only has an effect when Dart is compiled in AOT mode (see docs — not sure why that isn't in a more official location, but it's the personal domain of one of the Dart compiler's developers), and for Flutter apps that happens in release mode and profile mode but not debug mode. (Flutter debug mode uses the Dart VM's JIT mode, as part of how it accomplishes fast hot reload.) So whatever's causing the issue in debug mode, that pragma shouldn't be able to have any effect on at all. Here's how the issue currently reproduces for me:
Just now this reproduced for me on a few tries in a row; and it reproduced again after I added that pragma and then hit "run" in the IDE to build and install the updated app. By contrast, if I open the main app and then quit it in the same way, subsequent notifications still arrive promptly. (This was all on my Pixel 8 running Android 14.) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I spent some time today debugging this, and found the failure seems to happening at a deeper, earlier layer than I'd hoped. I don't yet have a diagnosis. The first key debugging step was to start using a local version of diff --git a/pubspec.yaml b/pubspec.yaml
index 3693e3652..dad3e99b7 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -50 +50,2 @@ dependencies:
- firebase_messaging: ^14.6.3
+ firebase_messaging:
+ path: ../firebase-flutter/packages/firebase_messaging/firebase_messaging Then Then I found that even public void onReceive(Context context, Intent intent) {
Log.d(TAG, "broadcast received for message"); (where Along the same lines, public class FlutterFirebaseMessagingService extends Service {
private static final String TAG = "FLTFire1MsgService";
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand: " + intent.toString());
return super.onStartCommand(intent, flags, startId);
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
} The outcome of that experiment is that This leaves me puzzled at what the variable is that causes the problem to arise here while things work great in zulip-mobile. It seems like the issue arises already before basically any of the code from One possible next step would be to do similar log-debugging on zulip-mobile, and confirm that the corresponding methods do get called there when the app wasn't running. On my current understanding of how notification delivery works, they have to be in order for the notifications to appear — which they do — but it'd be good to check that. If that's confirmed, then possibly the right next step is to make a hello-world app that receives notifications with |
… Well, I can no longer reproduce this issue myself. I don't reproduce it on a fresh install:
I had been reproducing this issue consistently on my existing install, even through lots of reinstalls/updates (but without ever uninstalling the app first) as I tried various changes for debugging. But at one point around thirty minutes ago I thought that #521 had fixed the issue for fresh installs, and so I went and replaced my main install with a fresh install to test that. The issue is indeed gone there now, but then just to confirm things I tried a fresh install from main and discovered that that also cleared up the issue. As a side effect of that testing, I no longer have an install of the app where the issue reproduces (and I don't know a way to make one, since fresh installs work fine). It's possible that this means this issue isn't a problem for normal users — that it was somehow a legacy of the many variations of the app, including all kinds of debugging code and other ad-hoc changes, that I'd installed on my device while developing notification support. We've had various reports of trouble with notifications, but I'm not aware of any that are clearly the same set of symptoms that I was seeing and that this thread is about; some I think were definitely #520, and others like "no sound" (above at #342 (comment)) remain undiagnosed but seem clearly distinct. I'll leave this open for now while I ask around (thread here) to see if I can find anyone who's actually seeing this same set of symptoms. If that doesn't turn up any cases, then we'll close it. |
That didn't, so closing this issue. From a user perspective, though, notifications on Android still won't work yet. After #521 (fixing #520) they work perfectly for me in a debug build… but they don't show up at all in a release build, even when the app is already running and even when it's in the foreground. Details in #528, which we'll track as a separate issue because the pattern of symptoms no longer matches the one this thread was about. |
This fixes part of zulip#528, following the suggestion n-92 made here: zulip#342 (comment) Even with this change, notifications still don't yet work on Android in release builds. But after this change, when the app wasn't in the foreground, they get farther than before. Specifically they get just as far as they get, with or without this change, when the app was in the foreground. Details here: zulip#528 (comment)
This fixes part of #528, following the suggestion n-92 made here: #342 (comment) Even with this change, notifications still don't yet work on Android in release builds. But after this change, when the app wasn't in the foreground, they get farther than before. Specifically they get just as far as they get, with or without this change, when the app was in the foreground. Details here: #528 (comment)
@n-92 @Itsamanjain This issue, and its siblings #520 and #528, are all fixed in today's new beta release v0.0.11. That means that notifications should now be working normally in the published release build of the beta app. Please try it out, and report issues or feedback with anything you notice! Thanks in particular @n-92 for the pointer on |
You are welcome. I am happy to contribute. |
In my draft implementation of #320, notifications appear just fine when the app is in the foreground, and also when it's running in the background. But when the app is not running at all — for example if you've swiped it away in the app switcher — and then get a message, it seems like the notification will usually not promptly appear.
On at least one occasion, the notification appeared several minutes later, after I'd gone and launched the app for the sake of other testing. I'm not sure how long it might be delayed if the user doesn't happen to independently launch the app; just now I tried it again, and it's been over 10 minutes and counting.
We don't have this problem in zulip-mobile, as far as I've ever noticed. So it should be entirely a client-side issue to solve.
The fix will probably involve taking over some of the work that the Java code in
package:firebase_messaging
does, for listening to the FCM service and acting on those messages. In zulip-mobile we do that work ourselves, in Kotlin, and then act on them within Kotlin as well. In a worst case we can always do the same here, but I'm hopeful that we can keep the application logic in Dart instead — we'd just need to be more eager in passing over to Dart thanpackage:firebase_messaging
is. But that will require investigation.(Even in that worst case where we do end up keeping application logic in Kotlin for notifications, we'll be in a much better position to share its application data with our Dart code (cf zulip/zulip-mobile#5117) than we were with React Native in zulip-mobile. Our accounts data is already in a nice clean SQLite table; and when we start storing from-the-server data, that will also be in reasonable tabular form from the beginning. And a critical aspect of any such data sharing would be integration tests spanning both sides (cf zulip/zulip-mobile#5589), which Flutter supports well and RN just catastrophically didn't.)
The text was updated successfully, but these errors were encountered: