简体   繁体   English

Android活动完成更新以前的活动

[英]Android activity finish update previous activity

I have an activity where you can click on a product and it adds it to a basket, a button is then pressed to checkout where a new activity is started, this activity lists everything in the basket with an option to remove the item. 我有一个活动,您可以点击产品并将其添加到购物篮中,然后按下按钮以结帐新活动的开始位置,此活动会列出购物篮中的所有内容以及删除商品的选项。 If ALL items are removed I am calling finish() on this activity to go back to the previous activity that listed all the products. 如果删除了所有项目,我将在此活动上调用finish()以返回上一个列出所有产品的活动。

The problem is that this previous activity still says X items have been selected, how can I get this to update or to reload? 问题是之前的活动仍然说已经选择了X项,我该如何更新或重新加载?

Many Thanks. 非常感谢。

You should put your refresh code inside the onResume method of your Activity . 您应该将刷新代码放在ActivityonResume方法中。

Take a look at the Activity Lifecycle here for more information: http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle 有关详细信息,请查看此处的活动生命周期: http//developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

Look at startActivityForResult and onActivityResult functions if you want to return information from child activity back to a parent activity. 如果要将子活动中的信息返回给父活动,请查看startActivityForResultonActivityResult函数。

onResume is called every time the task/app becomes active (for ex: screen off/on, switching to your app using task switcher etc) and you may not want to refresh the page in all these cases. 每次任务/应用程序变为活动状态时都会调用onResume (例如:关闭/打开屏幕,使用任务切换器切换到您的应用程序等),您可能不希望在所有这些情况下刷新页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM