如何在android中编写异步内容提供程序
我正在编写一个为其他应用程序提供搜索结果的内容提供程序。内容提供程序将请求发送到服务器并解析响应。现在它可以在没有异步调用的情况下成功工作。但是如果我想要一个异步内容提供程序,即创建一个线程在query()函数中。然后问题来了,我如何知道线程何时完成并得到结果。因为现在我刚刚新建一个线程,并启动它,但是,光标无法获取结果。任何人可以帮助我吗?谢谢!
i'm writing a content provider that provides search results for other applications.The content provider sends requests to server and parse response.now it can work successfully without asynchronous calls.but if i want a asynchronous content provider,that is,creating a thread in the query() function.and then comes the problem,how can i know when the thread is finished and has got the results.because now i just new a Thread,and start it,however,the cursor could not get results.anybody can help me?Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的应用程序也有同样的问题。根据您的情况,您也许能够从查询调用中返回空游标,然后在更新游标数据时更新您的视图。如果它对您的数据源有意义,您可以子类化 MatrixCursor (或另一个游标),并确保在异步请求完成后更新游标数据时调用 onChange - 这应该通知游标的观察者新数据,然后它们可以显示它。
My application has this same problem. Depending on your situation, you may be able to return an empty cursor from your query call, and then have your views update when the cursor's data is updated. If it makes sense with your data source, you can subclass MatrixCursor (or another cursor) and make sure to call onChange when the cursor's data is updated after the asynchronous request completes - this should notify that cursor's observers of the new data, and then they can show it.