jamesisaac / react-native-background-task

Periodic background tasks for React Native apps, cross-platform (iOS and Android), which run even when the app is closed.
MIT License
1.11k stars 110 forks source link

Task not triggering when app closed Android 9 / 10 #80

Closed OliEfr closed 4 years ago

OliEfr commented 4 years ago

I developed an app on Huawei Honor 5c (Android Version 4.0 - 7.0?), which worked perfectly fine with react-native-background task.

I switched the phone (Xiaomi Mi 9SE (MIUI Global 11.0.6 / Android 9) with the same project. The background task still executes when the app is in background unclosed. As soon as the app is killed, the task does not fire anymore. adb logcat logging does not show any (error) messages.

For Android 10, the background task does not fire at all, also when the app is left open in background.

I tried to find workarounds and tried other packages as well (react-native-background-jobs, react-native-background-fetch). However, none of this worked.

Unfortunately, I am new to Android programming and didn't find any related issues so far.

Did the headless implementation change with new android versions? Do I need to change something in my project for use with Android 9/10? Is there a way for better testing this issue? Do i need to write java code? I dont understand why it worked on previous Android versions.

react-native version: 0.61.4 react-native-background-task: 0.2.1

eazzyLEE commented 4 years ago

@OliEfr did you find a fix for this?? I keep getting: 08-21 19:06:41.895 28801 28801 D BackgroundTask: Setting foreground false 08-21 19:06:41.895 28801 28801 D BackgroundTask: Committing job schedule 08-21 19:06:47.051 28801 28801 D ReactNative: ReactInstanceManager.detachViewFromInstance() I think the ReactInstanceManager.detachViewFromInstance() prevents the job from running in my case.

OliEfr commented 4 years ago

No, I ended up using a different package. React-Native-Background-Job I think.

eazzyLEE commented 4 years ago

and did it work even for Android 10?? @OliEfr

OliEfr commented 4 years ago

It heavily depends on the phone and specific OS. You might need to prompt for battery permission etc.

Unfortunately, I found no easy one for all solution.