Rapsssito / react-native-background-actions

React Native background service library for running background tasks forever in Android & iOS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why the example looping is not incrementing values in background on Xiaomi (MIUI 13)

mlwong54 opened this issue · comments

Hi I set up the app as instructed and the background service seems working when opening the app

const veryIntensiveTask = async (taskDataArguments) => {
console.log(taskDataArguments)
const { delay } = taskDataArguments
await new Promise(async (resolve) => {
for (let i = 0; BackgroundService.isRunning(); i++) {
console.log(i)
await BackgroundService.updateNotification({
taskDesc: Adding steps... + i,
})
await sleep(delay)
}
})
}

but when i closed the app the console update just stop so as the BackgroundService.updateNotification
shouldn't this defeats the whole purpose of background action?
it should be looping infinitely but the notification stops refreshing after the app went background.
what is happening?

I am running the app on Redmi 12C(Android 12). Is this the cause for the inactivity?

Oh I found out that the MIUI will kill the background task aggressively.
I tried using the solution here but to no avail: https://dontkillmyapp.com/xiaomi
If someone uses Xiaomi phone with MIUI, please tell me if you have solve the problem.