Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

The problem is that this previous activity still says X items have been selected, how can I get this to update or to reload?

like image 622
Paul Blundell Avatar asked Dec 14 '25 15:12

Paul Blundell


2 Answers

You should put your refresh code inside the onResume method of your Activity.

Take a look at the Activity Lifecycle here for more information: http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

like image 195
Tiago Pasqualini Avatar answered Dec 16 '25 08:12

Tiago Pasqualini


Look at startActivityForResult and onActivityResult functions if you want to return information from child activity back to a parent activity.

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.

like image 22
vishalb Avatar answered Dec 16 '25 06:12

vishalb