Skip to content
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

Closed
atlanteh opened this issue May 1, 2017 · 7 comments
Closed

headlesstask wake-lock consumes battery #13720

atlanteh opened this issue May 1, 2017 · 7 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@atlanteh
Copy link
Contributor

atlanteh commented May 1, 2017

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

  • React Native version: 0.41.2
  • Platform: android
  • Development Operating System: windows
@hramos hramos closed this as completed Jun 26, 2017
@atlanteh
Copy link
Contributor Author

Why did you close this issue? Is it solved?

@atlanteh
Copy link
Contributor Author

atlanteh commented Jul 2, 2017

@hramos Can you please explain why you closed this issue? It still happens to me..

@oriharel
Copy link
Contributor

@atlanteh maybe you need to call onHeadlessJsTaskFinish() instead of stopSelf() directly.

@atlanteh
Copy link
Contributor Author

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.
Do you have any insights on this?

@oriharel
Copy link
Contributor

oriharel commented Sep 13, 2017

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).

@oriharel
Copy link
Contributor

Also, maybe try to update React Native to latest and see if it reproduces.

@atlanteh
Copy link
Contributor Author

I must call the acquireWakeLockNow in the broadcast receiver. See the docs:

If you start your service from a BroadcastReceiver, make sure to call HeadlessJsTaskService.acquireWakeLockNow() before returning from onReceive().

This is to prevent the phone from falling asleep before actually starting the service.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants