Open Sandeep-GitAcc opened 4 years ago
From your example and questions, I think it would be helpful to know your use-case. This plugin is focused around the service - in other words, executing dart code continuously at set intervals.
If notifications are your focus, try instead: https://pub.dev/packages/flutter_local_notifications
Use case:
Above polling + scan won't take longer than 30 seconds.
Example: Whatsapp run a sync-up process at some interval and show notification if we have any new message. So here sync-up process is similar to running _foregroundservice at set interval. And showing notification is similar to using _flutter_localnotification
I have a different code in fireNotification() method (polling, scanning payload), here I have put an example code to reproduce the error. The method fireNotification() would have been called and notification would be updated. But this is not the case here.
1 . Why logs were never printed? Is the service not running? When I call kill the app, my console disconnects so I couldn't monitor if the logs are being printed in background.
- On first launch I can see the notification I set before calling startForegroundService(), but after the schedule time notification doesn't change. If I kill the app and start again, notification set in the method is displayed. Why this behaviour?
- What are these extra logs that are being printed?
These questions are mostly related why the service is behaving the way it is. I couldn't find nothing related to these queries. Can you please explain them a bit? May be document the same. Also I would like to add one more unclear functionality,
My other 3 queries were mostly related to notification which now I am trying to accommodate under _flutter_localnotification.
Almost definitely android_alarm_manager is a better choice (in combination with flutter_local_notification) for your use case.
To answer your questions, though:
If the notification shows up, the service is definitely running. The service is an Android thing, though - whether the Dart code is being run is a different deal. The full text of your main.dart would probably help with looking at that.
If the notification is there, that means the app/service is already running. There are some things to get used to with flutter debugging - usually it works fine but there can be strange things, especially with hot reload/restart. Qutting the Flutter debug process entirely and redoing flutter run
is what I've found to be the most reliable when debugging, but if it doesn't work try completely uninstalling the app and doing flutter clean
before trying flutter run
again.
Those messages come from Flutter, not this plugin - likely debug info related to performance, since Flutter is built around UI/high performance.
I have following methods defined in a dart file:
Following log
was never written.
I can also see some logs
being printed continuously.
Some queries