SyncAdapter stays awake for hours on end

戏子无情 提交于 2019-12-08 03:30:04

问题


My Android app uses a SyncAdapter to sync with my API service. I use delayUntil to tell it to only sync every half an hour. However, some users are reporting incidents where it never goes to sleep again once it's done, draining the phone battery (e.g. the app shows up in the device's battery page showing a "Keep awake" of 13 hours+).

I'm also certain there's no infinite loops in the onPerformSync method - it makes a few HTTP calls and updates the database and that's about it.

Has anybody else ever experienced anything like this, and if so, what was behind it?


回答1:


Look in your Application onCreate method. The mistake I made was assuming that the Application only ever starts up when the user interacts with your app, but in fact the Application starts every time the SyncAdapter does its stuff. In my case the Application's onCreate method was telling Dropbox to start syncing, and the code designed to make Dropbox stop syncing never kicked in (it happened when the last Activity was shut down - which of course never happened because there were no Activities when just the SyncAdapter was running) so it never went to sleep again.



来源:https://stackoverflow.com/questions/28673639/syncadapter-stays-awake-for-hours-on-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!