easazade / android_long_task

android long task is a flutter plugin to run dart code in an android foreground service with simplicity
Apache License 2.0
16 stars 6 forks source link

Stop service when app killed #8

Closed Farrukh1198 closed 2 years ago

Farrukh1198 commented 2 years ago

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.

easazade commented 2 years ago

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?

Farrukh1198 commented 2 years ago

Thank you for your reply. I'm making taxi driver app and they can't get orders when they minimizes the app. And now they're getting orders even if they are not working at the moment. Or can I show stop button on service notification?

чт, 27 янв. 2022 г., 8:27 AM alireza easazade @.***>:

Reopened #8 https://github.com/easazade/android-long-task/issues/8.

— Reply to this email directly, view it on GitHub https://github.com/easazade/android-long-task/issues/8#event-5960852620, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXPHHODN34MLWSAJRPCHOKDUYC3TDANCNFSM5M253IVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you modified the open/close state.Message ID: @.***>

easazade commented 2 years ago

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

Farrukh1198 commented 2 years ago

Ok, thanks.

чт, 27 янв. 2022 г., 2:54 PM alireza easazade @.***>:

there is no stop or cancel button feature in this plugin

— Reply to this email directly, view it on GitHub https://github.com/easazade/android-long-task/issues/8#issuecomment-1023032970, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXPHHOH5ODN6KJYZ53Y5JC3UYEI47ANCNFSM5M253IVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you modified the open/close state.Message ID: @.***>

Farrukh1198 commented 2 years ago

Another question. I tried to build release app. But it's not working properly

чт, 27 янв. 2022 г., 2:56 PM Фаррух Ахунов @.***>:

Ok, thanks.

чт, 27 янв. 2022 г., 2:54 PM alireza easazade @.***>:

there is no stop or cancel button feature in this plugin

— Reply to this email directly, view it on GitHub https://github.com/easazade/android-long-task/issues/8#issuecomment-1023032970, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXPHHOH5ODN6KJYZ53Y5JC3UYEI47ANCNFSM5M253IVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you modified the open/close state.Message ID: @.***>

easazade commented 2 years ago

have you annotated the serviceMain function with

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

also take look at this issue

Farrukh1198 commented 2 years ago

Yes, I did. I'm rebuilt app and now it's work fine 👌👍👍 thank you so much for your reply and your plugin it's the best plugin for foreground service 👍. And another question can I work with multiple services using this plugin?

чт, 27 янв. 2022 г., 8:45 PM alireza easazade @.***>:

have you annotated the serviceMain function with

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

— Reply to this email directly, view it on GitHub https://github.com/easazade/android-long-task/issues/8#issuecomment-1023352575, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXPHHOGYZPRJLWYDJX4HPZ3UYFSARANCNFSM5M253IVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you modified the open/close state.Message ID: @.***>

easazade commented 2 years ago

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

Farrukh1198 commented 2 years ago

Ok, got it. Last question, sorry for being annoying, when I minimize the app service starts when I return to the app service stops but I get this message "Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++." Is it related to long task plugin? After that my service doesn't work properly. Like I said I use service to get data from service via SSE(Server Sents Events) but after about 30 mins I'm not getting any messages.

чт, 27 янв. 2022 г., 11:25 PM alireza easazade @.***>:

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 https://pub.dev/packages/flutter_local_notifications plugin to show different notifications for each task you are running in you're foreground service

— Reply to this email directly, view it on GitHub https://github.com/easazade/android-long-task/issues/8#issuecomment-1023518547, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXPHHOEYWVIZJRFVU2EN35LUYGE2NANCNFSM5M253IVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you modified the open/close state.Message ID: @.***>