Issue
I am implementing a stopwatch (0 to .. seconds counter) in my app. I succesfully implemented it in my Dart code, but I need it to work even if the app is closed/unloaded from memory, etc. Therefore I need a foreground service with an ongoing notification and a counter in it.
I have read and watched about every question/article/video on the internet about integrating an Android foreground service in a Flutter app. And still after several days I did not find a simple and explanatory example on how to do it. I followed this official tutorial and succeeded in connecting Flutter side to Kotlin code https://flutter.dev/docs/development/platform-integration/platform-channels . But I still do not understand how do I launch a foreground service. And where is it better to implement my counter, in the Kotlin service or in dart? Would appreciate any help.
Solution
You can read about foreground service here https://developer.android.com/guide/components/foreground-services You should implement your counter in the service because dart doesn't work in background. And call start/stop from dart through platform channels.
Answered By - IL_Agent
Answer Checked By - Candace Johnson (JavaFixing Volunteer)