JulianAssmann / flutter_background

A flutter plugin to keep apps running in the background via foreground services. Android only.
https://pub.dev/packages/flutter_background
MIT License
89 stars 52 forks source link

Initialize without a notification? #24

Closed willhaslett closed 3 years ago

willhaslett commented 3 years ago

My use case does not involve creating notifications, but It seems that I can't initialize the FlutterBackground object without generating a notification. I see how the default constructor for FlutterBackgroundAndroidConfig includes dummy values for a notification, but does the 'initialize' call to the MethodChannel necessarily generate a notification?

JulianAssmann commented 3 years ago

Yes, unfortunately a foreground notification is required by Android to enable foreground services used by this plugin. See here for more information on that.

What exactly are you trying to achieve? Maybe there is a way without a notifications requirement to achieve it...

willhaslett commented 3 years ago

@JulianAssmann ah, I see. I simply need to keep the app alive for periodic sensor data acquisition (users are aware of this and agree, it's a research app). I actually do want to created notifications when the app is backgrounded under certain logical conditions, was just curious if that first notification was necessary. Now I understand. Thank you.

And thanks for this plugin. Keep-alive is so tricky and for Android this makes life much easier.

JulianAssmann commented 3 years ago

Yes, it's really confusing on Android, I agree. But at least it's possible at all (looking at you, iOS :))

However, if you only want to execute some code periodically, there is the option of so called WorkManagers and there is even a workmanager plugin for it in Flutter. Maybe this is enough for you.

JulianAssmann commented 3 years ago

Closing this issue due to inactivity. Feel free to reopen at any time.