SyncAdapter保持清醒的几个小时就结束 [英] SyncAdapter stays awake for hours on end

查看:179
本文介绍了SyncAdapter保持清醒的几个小时就结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Andr​​oid应用程序使用 SyncAdapter 来与我的API服务同步。我使用 delayUntil 来告诉它只能同步每半小时一班。然而,一些用户报告事故的地方从不一旦完成再睡觉,耗尽手机电池(例如应用在设备的电池页面显示了呈现出保持清醒13小时+)。

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

我也一定有一个在 onPerformSync 方法没有无限循环 - 这让一些HTTP调用和更新数据库,仅此而已。

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?

推荐答案

看看你的应用程序的onCreate 方法。我犯了这个错误是假设应用程序,当用户使用你的应用程序进行交互只会启动,但实际上在应用程序启动每次SyncAdapter做它的东西的时间。在我的情况下应用程序的的onCreate 方法告诉Dropbox的启动同步,而code旨在使Dropbox的停止同步功能(它发生了,当最后一个活动是从来没有踢关闭 - 这当然是从来没有发生过,因为有的时候只是SyncAdapter正在运行任何活动),因此它永远不会又睡着了。

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.

这篇关于SyncAdapter保持清醒的几个小时就结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆