Why does the sync adapter won't work if android storage space running out

心不动则不痛 提交于 2020-08-09 08:25:40

问题


In my android application I have configured a periodic syncing using sync adapter, and its working fine except if the android storage space is running out.If i deleted some files and free up space then sync will start to work.Actually I am just syncing data from my device to the remote server,so there is no need for extra space in device while syncing.So why does the android sync adapter demand some space to work.What I noticed is the sync adapter won't work even if there is a 2% free memory is in the device.Similary I found that the gmail application in android device also won't work if 98 percentage of device memory is used.Gmail will show a couldn't sync message and will not sync and receive any message if device memory is full.So is there any way to start the sync adapter if the memory is full? If not then how can i notify my application users about this fact?


回答1:


This is standard AOSP/Android behaviour.

  1. The SyncManager listens to the Intent.ACTION_DEVICE_STORAGE_LOW intent that is sent when the device is low on storage and cancels any active syncs

  2. It also listens to the Intent.ACTION_DEVICE_STORAGE_OK intent in order to find out that the storage is back to normal and reschedules the syncs

It does this probably because it is backed up by the SyncStorageEngine that stores various information in XML files

Though this answer is late, if you want to notify your users, On Android Oreo and below you can listen to the same broadcasts and notify them. From Android Oreo it gets a bit more tricky as the recommendation is to use the Context.getCacheDir() in order to manage your cache space. Refer to this answer for more details



来源:https://stackoverflow.com/questions/41936001/why-does-the-sync-adapter-wont-work-if-android-storage-space-running-out

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