java - 有没有办法知道谁在调用同步适配器?
问题描述
我的项目中有内容提供者和同步适配器。在我的项目中,首先我将从服务器获取数据,然后将其存储在我的数据库 sqlite 中。
现在我来谈谈我的问题。其实我想根据sqlite中修改的数据来改变服务器数据。
例如:如果我删除数据库中的数据,我还想删除服务器数据库中的数据。为此,我的同步适配器应该知道执行了什么操作,例如删除或插入。
另一种方法是在调用同步适配器时将我的整个本地 sqlite 数据库与服务器中的数据进行比较。
我不想要那种方法。有什么方法可以知道谁在调用同步适配器或同步适配器在内容提供程序中执行了什么操作?
解决方案
术语“谁在调用同步适配器”似乎没有什么价值,只要它不会给你任何有用的信息。相反,您很可能希望在有人要求同步时传递一些参数(通过requestSync()
)。
ContentResolver.requestSync(Account, String, Bundle)
Bundle
接受将传递给您SyncAdapter
的额外内容onPerformSync()
:
// a code that initiates sync
ContentResolver.requestSync(ACCOUNT, AUTHORITY, someBundle);
...
// your implmementation of SyncAdapter
@Override
public void onPerformSync(
Account account,
Bundle extras, // acquire information from this bundle
String authority,
ContentProviderClient provider,
SyncResult syncResult) {
/*
* Put the data transfer code here.
*/
...
}
推荐阅读
- javascript - Object.keys() 返回在 Ant Design 表格列渲染中不起作用
- javascript - 如何使用 localstorage 和 Jquery 从多个点击事件中生成一个包含一组存储值的对象键
- python-3.x - TypeError: 'float' 对象不能被解释为 stride_trick.as_strided 中的整数
- unity3d - 如何从 Mixamo 中删除上传的角色
- regex - 使用正则表达式确定这两种情况
- typescript - “”的这种行为是 TypeScript 类型系统错误吗?
- physics-engine - PAL(物理抽象层)仍然是一个可行的实用程序吗?
- docker - GitHub Actions:获取所有作业命令以在 Docker 容器中运行
- python - 如何在 Keras 中的 layers.concatenate() 之后规范化数据输入
- c++ - 特征实例作为不同特征的模板参数