- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我对此进行了很多搜索,但找不到任何解决方案。很长一段时间以来,我一直在使用 Volley 来处理我的网络通信。最近我决定使用 SyncAdapter
将我的数据同步到服务器。在 onPerformSync()
方法中,我想我将使用 Volley 将数据发送到服务器,因为使用 Volley 可以很容易地发出 GET、POST 请求。
问题 - SyncAdapter
和 Volley 都使用它们自己的独立线程。因此,当我从 onPerformSync()
方法内部发起 Volley 请求时,SyncAdapter
不会等待 Volley 请求完成并在 onResponse 之前完成同步()
或 onErrorResponse()
接收到 Volley 的回调。在第一次调用成功返回后,我需要在 SyncAdapter
中进行进一步的网络调用。
示例代码 -
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
ContentProviderClient provider, SyncResult syncResult) {
JsonObjectRequest jReq = new JsonObjectRequest(Method.POST, url, data,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i(TAG, "response = " + response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "error = " + error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(jReq);
//onPerformSync() exits before request finished
}
问题 - 那么如何让 SyncAdapter
等待 Volley 收到网络响应?
最佳答案
发出同步截击请求。
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest request = new JsonObjectRequest(URL, null, future, future);
requestQueue.add(request);
然后使用:
try {
JSONObject response = future.get(); // this will block (forever)
} catch (InterruptedException e) {
// exception handling
} catch (ExecutionException e) {
// exception handling
}
关于android - 将 Volley 与 Sync Adapter 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35824502/
是否可以使用 MS Sync Framework 同步不同数据库中的不同表(具有完全不同的结构),假设其中一个表具有主键,另一个具有唯一索引,其值与第一个表的 PK 一致(但不能晋级PK)?列名也可以
我正在开发一个使用 Twilio Sync 作为数据库的应用程序。我确实订阅了很多事件,例如 itemAdded、itemUpdated、itemRemoved,以使用 Sync Javascript
我们计划使用 ADO.NET 的同步服务将商店与总部同步,有人建议我通过 进行同步。 WCF 代理 . 通过 WCF 代理同步是否意味着我将能够 通过 http 同步 ?如果没有,是否可以使用同步服务
在 Sync Framework 2.1 中,批处理似乎得到了内置支持,因此在某些提供程序中,我们可以只提及批处理大小和假脱机文件位置(以及一些其他属性),批处理将得到处理。开发人员不必编写自己的批处
'sync' 事件和 Backbone.sync 有什么区别? ...它们分别是什么? 最佳答案 虽然两者都与向服务器同步数据的任务有关,但两者之间没有任何联系。 Backbone.sync实现您的
在 Go 中,我们可以使用: type Data struct { lock *sync.Mutex } 或 type Data struct { lock sync.Mutex
我们在各种客户项目中使用 Microsoft Sync Framework 2.1 进行文件和数据库同步。扩展支持将于 2021 年结束。 所以我的问题是: 微软的同步框架策略是什么?它会是开源的,所
我在这个站点和其他站点上看到了一些帖子,指出问题通常是由将表添加到客户端的 SyncAgent 配置或提供者端的 SyncAdapter 的顺序引起的。我相信我在这两个地方都正确地对表格进行了排序(我
Using an Asynchronous Controller in ASP.NET MVC 的使用 BeginMethod/EndMethod 模式部分指的是 Sync() 方法。它没有链接,我无
这是代码: type someThing struct { sync.Mutex cv *sync.Cond num int } func NewSometh
异步地做多项工作(排序向量,主要是函数计算(计算是计算或内存限制,目前,我可以用以下方式编写这些操作: 使用 Threads.@spawn _f1 = Threads.@spawn f1(x) _f2
我想使用 Rust 和 once_cell实现一些静态常量结构实例,一个静态常量向量包含这些静态结构实例。 示例代码如下: use once_cell::sync::Lazy; pub struct
我想使用 Rust 和 once_cell实现一些静态常量结构实例,一个静态常量向量包含这些静态结构实例。 示例代码如下: use once_cell::sync::Lazy; pub struct
看了sync.Pool的设计,发现是两个逻辑,为什么要用localPool来解决锁竞争。我们可以只使用 chan 来实现一个。 使用 channel 比 sync.pool 快 4 倍! pool除了
我有一个编码为在模糊时运行 save_notes 函数的文本区域。当 save_notes 调用时,我在控制台中得到以下内容: TypeError: Cannot read property 'syn
如果 Waitgroups 和 Mutex 总是需要通过引用传递,我们不能把它做成引用类型(禁止使用它们作为值传递)吗?我的意思是有没有我们需要使用它们按值传递的用例? 最佳答案 当您将任何参数作为值
背景:我正在尝试创建一个完全异步 Node js 演示的小测试。然后我可以看到一个好的样本是什么样的,以便清理我完成的其他一些项目。 这是我的代码 //https://medium.com/@tkss
http://msdn.microsoft.com/en-us/library/dd918848.aspx “了解作用域是表和筛选器的组合很重要。例如,您可以定义一个名为 sales-WA 的筛选作用
我尝试同步我的 Visual Studio 代码设置/扩展。我手动执行的许多同步步骤。 然后我发现了这两个工具 https://code.visualstudio.com/docs/editor/se
我正在尝试移植一个扩展,但我的 JS 非常生疏。 https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Chro
我是一名优秀的程序员,十分优秀!