easazade/android_long_task

Stop service when app killed

Farrukh1198 opened this issue · 9 comments

How to stop the service when app is killed or exited? I successfully initialized the service, it's working fine when I minimize app. But it still working when I exit app and I want to stop it when I exit the app. Please help me.

you can watch for flutter app lifecycle state called AppLifecycleState.detached.
checkout this stackoverflow answer
may I ask what is the point of using service when you want to kill it when the app is killed?

there is no stop or cancel button on notification feature in this plugin. PRs are accepted though :))

have you annotated the serviceMain function with

@pragma('vm:entry-point')
serviceMain() async {

also take look at this issue

No. you can only run one Foreground Service using this plugin. I also never seen an android app run 2 foreground services at the same time. even if it is possible, if you want to handle multiple tasks in services, it's best to use one service for all of them since in newer android versions there is always a possibility that OS might kill the foreground service. (it's a low possibility). if you run multiple services. you increase this possibility. that being said you may need to show multiple notifications since you are running different tasks and you might want to show user the progress for each task. I think this can be achieved using flutter_local_notifications plugin to show different notifications for each task you are running in you're foreground service