flutter_background_service icon indicating copy to clipboard operation
flutter_background_service copied to clipboard

isServiceRunning

Open dmrcierhn opened this issue 4 years ago • 11 comments

isServiceRunning returns true even though the service is not running. How can i fix this ? Thank you!

dmrcierhn avatar Jan 15 '21 14:01 dmrcierhn

I met the same problem. sometime when restart app , we need to know whether service is running or not ,if running, then to load resources.

tranice avatar Feb 07 '21 03:02 tranice

The service will continue running until you call stopService () from inside the method you used when initializing the service.

ekasetiawans avatar Feb 07 '21 03:02 ekasetiawans

in fact ,sometime we didn't start bg service when app was starting such as geo location, so when app is starting we need to know whether the bg service is running or not , if running ,we need to load some existing resource . existing functions are excellent ,so it will be great that add support to check bg service running status .

tranice avatar Feb 07 '21 04:02 tranice

@tranice I'm not sure I understand what you want. You can't see whether the background service is running or not without the UI. So, if you want to make sure that the service is running, you can simply create a notification. However, if you want to get that status from the UI, you can use isServiceRunning from the UI. You can't use isServiceRunning from within the service itself, because if you do, it means the service is running.

ekasetiawans avatar Feb 07 '21 05:02 ekasetiawans

void main(){
...
FlutterBackgroundService.initialize(onStart);
...
}

void onStart(){
// everytime commands executed inside this method, its mean the service is running.
}

ekasetiawans avatar Feb 07 '21 05:02 ekasetiawans

emm excuseme i want to ask something to you

Why i run this flutter service then i try to close my app and open again, but my app cant open? in my display just there are white blank page. how to resolved this issue

PilotJinix avatar Mar 08 '21 00:03 PilotJinix

Hi @PilotJinix, I am facing the same problem let me know you resolve this issue.

Surya-ufours avatar Mar 09 '21 06:03 Surya-ufours

@PilotJinix @Surya-ufours could you provide the flutter doctor output?

ekasetiawans avatar Mar 09 '21 06:03 ekasetiawans

Hi @ekasetiawans, I am using your example app, it's working fine in close app and open again scenario.

This is my flutter doctor output

[✓] Flutter (Channel master, 1.26.0-2.0.pre.14, on Linux, locale en_IN)
    • Flutter version 1.26.0-2.0.pre.14 at /home/ufours14/flutter
    • Framework revision f37969638d (3 months ago), 2020-12-14 22:18:03 -0500
    • Engine revision 1749dbcc1b
    • Dart version 2.12.0 (build 2.12.0-150.0.dev)

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /home/ufours14/Android/Sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /home/ufours14/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Android Studio
    • Android Studio at /home/ufours14/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (2 available)
    • RMX1911 (mobile) • fe59ac8b • android-arm64  • Android 10 (API 29)
    • Chrome (web)     • chrome   • web-javascript • Google Chrome 88.0.4324.182

Surya-ufours avatar Mar 09 '21 06:03 Surya-ufours

@PilotJinix @ekasetiawans, I think its working fine in flutter run --release (release build)

Surya-ufours avatar Mar 09 '21 06:03 Surya-ufours

@PilotJinix @Surya-ufours I cant reproduce the issue on my machine. I use stable channel (2.0.1). I got an exception, but the display is still working. I have fill an issue to flutter repository https://github.com/flutter/flutter/issues/77680.

ekasetiawans avatar Mar 09 '21 07:03 ekasetiawans