Dev-hwang / flutter_foreground_task

This plugin is used to implement a foreground service on the Android platform.
https://pub.dev/packages/flutter_foreground_task
MIT License
149 stars 109 forks source link

[Question] Should I restart Foreground service in `onNotificationDismissed` (Android 14) #247

Closed WingCH closed 3 months ago

WingCH commented 3 months ago

https://developer.android.com/about/versions/14/behavior-changes-all#non-dismissable-notifications

I know that Android 14 allows users to turn off foreground service notifications.

Will dismissing the notification stop the foreground service from running?

Should I restart the foreground service when I receive onNotificationDismissed?

Dev-hwang commented 3 months ago

@WingCH

Even if notification is dismissed, the foreground service does not stop immediately, but foreground service may become less importance.

This means that the service may experience delays or the Android OS may kill the service.

The best way in this situation is to use updateService function when the onNotificationDismissed event is fired.

@override
void onNotificationDismissed() {
  print('onNotificationDismissed');

  // Show notification again~
  FlutterForegroundTask.updateService();
}
WingCH commented 3 months ago

Thank you for your quick and detailed response.

I have another question: If I don't have a need to update the UI, and I do not include the following code:

FlutterForegroundTask.initCommunicationPort();

Will it affect the stability of the foreground service?

Dev-hwang commented 3 months ago

@WingCH

There is no need to initialize if there is no communication between main isolate(UI) and background isolate(TaskHandler).

No impact to service :)

WingCH commented 3 months ago

thanks~