Neelay Srivastava
Neelay Srivastava

Reputation: 1241

Foreground Service in flutter not working

I am trying to implement foreground service in flutter I tried this plugin but i am facing the error when i try to run the service and i am not able to show any notification either my package name is com.example.flutterforeground3 and i register the service in the manifest like this <service android:name="com.example.flutterforeground3.ForegroundService"/> and i also added the notification icon but still i am getting error when trying to run the service

Service cannot be started.  Did you register ForegroundServicePlugin as a service in your android manifest?
E/flutter ( 6131): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: sendToPort was called in main isolate before setupIsolateCommunication for background isolate was called.
E/flutter ( 6131): #0      ForegroundService.sendToPort (package:foreground_service/foreground_service.dart:95:7)
E/flutter ( 6131): <asynchronous suspension>
E/flutter ( 6131): #1      _MyAppState.build.<anonymous closure> (package:flutterforeground3/main.dart:111:43)
E/flutter ( 6131): <asynchronous suspension>
E/flutter ( 6131): #2      _MyAppState.build.<anonymous closure> (package:flutterforeground3/main.dart)

Upvotes: 1

Views: 1914

Answers (1)

alireza easazade
alireza easazade

Reputation: 3872

you can use android_long_task plugin which uses Foreground Service to run a long running task in android. you can run a task as a Future and await for it. you can also listen for for task updates if you have any from a Stream. you can leave your app and your service will still run. start it again and you can listen for the task data update again. check it out

Upvotes: 1

Related Questions