-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
headlesstask wake-lock consumes battery #13720
Comments
Why did you close this issue? Is it solved? |
@hramos Can you please explain why you closed this issue? It still happens to me.. |
@atlanteh maybe you need to call onHeadlessJsTaskFinish() instead of stopSelf() directly. |
I don't think so. onHeadlessJsTaskFinish() is meant after a task is finished, not when it was never executed. I left this specific task a long time ago, but now I see that some other modules implement it and you can see here, for example, that they don't call stopSelf() or anything, just return null. so maybe this is the problem. |
I haven't got this far with HeadlessJsTaskService. My issues revolve around ReactContext created not on the main thread. see #15915. However, I did notice that inside HeadlessJsTaskService.startTask() there is already a call to acquireWakeLockNow(). So with your call from the receiver that makes it 2 calls. Maybe you can drop the call from the receiver (I know we are told to do so from the documentation but worth a shot). |
Also, maybe try to update React Native to latest and see if it reproduces. |
I must call the acquireWakeLockNow in the broadcast receiver. See the docs:
This is to prevent the phone from falling asleep before actually starting the service. |
I have a headless task that wakes up every 30 minutes. does some work for 1-2 seconds and finishes. However I see that the wake-lock is held much much longer than necessary. The battery is draining like crazy. I thought this might be something with my code, so I created an empty project with just my headless task code, but the wake-lock keeps draining the battery. I added logs and I see that the services is destroying after the task is done, so it's releasing the wake-lock acquired in the receiver. So either I'm doing something wrong, or the problem is in react-native.
I uploaded my demo example here:
https://github.com/atlanteh/headlesstask-battery-consumption-example
The text was updated successfully, but these errors were encountered: