Android 在完成另一个 Activity 时重新启动 Activity(使用 AsyncTask)
我想标题有点令人困惑,但这就是我想要做的:
我有一个名为 ManageClass
的类,它列出了数据库的条目。我在ManageClass
中编写了另一个私有类,它扩展了AsyncTask
,以便我可以在从数据库获取数据时显示进度对话框。现在,当我单击某个项目时,我会创建一个新的 Intent,它将带我进入我的 ViewItem
类。我在那里添加了一个按钮,以便用户可以删除他/她正在查看的特定条目。以上所有工作都很好。
现在我想在删除该条目后终止该活动并返回到上一个(显示列表的那个),但我想刷新列表。
我的问题是我无法使用 onResume()
因为在 AsyncTask
完成后恢复活动时它也会被调用。
有人能帮我吗?我真的很困惑...欢迎所有想法!
I suppose the title is a bit confusing but here is what I'm trying to do:
I have a class called ManageClass
which lists the entries of a database. I have written another private class within ManageClass
which extends AsyncTask
so that I can display a progress dialog while I'm getting the data from the database. Now when I click on an item I create a new Intent which takes me to my ViewItem
class. I've added a button there so that the user can delete that particular entry that he/she is looking at. All of the above work fine.
Now I want after deleting that entry to kill the activity and go back to the previous one (the one displaying the list) but I want to refresh the listings.
My problem is that I cant use onResume()
cause it will also be called when the activity is resumed after the AsyncTask
finishes.
Could anyone help me with that? I'm really stuck... all ideas are welcome!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我了解您的应用程序工作流程,您应该使用
startActivityForResult
而不是通过意图启动新的 Activity。看看这里一些例子
基本上你可以启动一个新的活动并通过“opener”活动的回调等待结果。这样您就可以避免将逻辑放入
onResume
方法中If I understand your app workflow you should use
startActivityForResult
instead of launching a new Activity via intent.Look at here fore some example
Basically you can launch a new Activity and wait for a result via callback on the "opener" activity. so you can avoid to put your logic into
onResume
method