如何从 AsyncTask 查询另一个活动中的游标?
我有一个从 Activity1 和 Activity2 调用的 AsyncTask 现在可见。从 Activity2 中,我对正在运行的 AsyncTask 进行了一些更改,并且 AsyncTask 必须在 Activity2 中重新查询游标。
如何验证 Activity2 是否可见并从 AsyncTask 中重新查询游标?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有点困惑->你想重新查询一个游标,它不在你的 AsyncTask 中,而是在你的 Activity 中?确切地说,您不使用 AsyncTasks 在单独的线程中执行数据库查询吗?那么你为什么要这样做呢?关于如何(尝试)检测您的活动是否可见的主题,已经有一个答案
编辑:
您应该有将 AsyncTask 定义为 Activity 的私有类(我假设您对 Activity1 是这样做的)。 AsyncTask 中的所有方法(doInBackground() 除外)都在您定义任务的 Activity 的 UI 线程上执行。
您不必直接调用 onProgressUpdate(),而是必须使用 publishProgress(),但我认为你不能从你的 Activity2 中调用它。
我不确定您到底想要实现什么,但也许您应该考虑查看 处理程序。
I am a little confused -> you want to requery a cursor, that is not in your AsyncTask, but in your Activity? Don't you use AsyncTasks, exactly, to do DB Queries in separate Thread? So why would you like to do that? On the subject of how to (try to) detect if your activity is visible, there's already an answer
EDIT:
You should have defined the AsyncTask as private class to an Activity (I assume you did it like that for Activity1). All methods in AsyncTask, except doInBackground() are executed on the UI Thread of the Activity you've defined the task in.
You don't have to call directly onProgressUpdate(), instead you have to use publishProgress(), but I think you cannot call it from your Activity2.
I am not sure what exactly you're trying to achieve, but maybe you should consider looking at Handlers.