如何检查哪个活动已完成
在我的 Android 应用程序中,我需要重写 onResume() 方法来检查两个可能的活动中哪一个刚刚完成。用户要么输入金额,要么指定并选择类别的百分比。我怎样才能做到这一点?另外,如果用户按 home 键然后返回我的应用程序,是否会调用 onResume() ?如果是这样,我可以调用 super.onResume(),对吗?
我有三个类:PaySaver、NewSavingCategory 和 NewPaycheck。 PaySaver.java 是主要 Activity,有两个按钮:New Paycheck(启动一个对话框,用户在其中输入 $ (NewPaycheck.java))和 New Saving Category(启动一个对话框,用户在其中输入姓名和 % ( NewSavingCategory.java))。当通过输入按钮关闭对话框时,我希望使用输入的信息更新主要活动。
谢谢!
In my Android application I need to Override the onResume() method to check which of two possible activities just finished. The user will either have entered an amount of money, or named and chosen a percent for a category. How can I do that? Also, if a user presses home and then goes back to my app, is onResume() called? If so, I can just call super.onResume(), right?
I have three classes: PaySaver, NewSavingCategory, and NewPaycheck. PaySaver.java is the main Activity, and there are two buttons: New Paycheck (launches a dialog box where a user inputs $ (NewPaycheck.java)) and New Saving Category (launches a dialogbox where a user inputs a name and a % (NewSavingCategory.java)). When the dialog box is closed via an enter button, I want the main activity to be updated with the information entered.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最有可能的是,你不知道。这两项其他活动都更新了您的中央数据模型。在
onResume()
中,您可以从同一中央数据模型更新 UI。因此,用户来自哪里并不重要——您正在获取最新的数据。关于他们返回的活动,是的。
您不仅“可以”做到这一点,而且必须调用
super.onResume()
,否则您的 Activity 将崩溃。Most likely, you don't. Both of those other activities updated your central data model. In
onResume()
, you update your UI from that same central data model. Hence, it does not matter where the user came from -- you are grabbing the latest data.On the activity they return to, yes.
Not only "can" you do that, you have to call
super.onResume()
, or your activity will crash.