Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I refresh a previous activity after the back button is pressed?

I am building an alarm application. I currently have a ListActivity which display the list of alarms and another activity which changes the time of a particular alarm. My problem is, when I decide to enter into the activity to change the time of an alarm and then I press the back button, it does not refresh. However, I've implemented a button that redirects back to the ListActivity and if I press it, the list of alarms are refreshed. How can I, after pressing the back button, refresh the list of alarms?

like image 832
Johnathan Au Avatar asked Dec 02 '22 19:12

Johnathan Au


2 Answers

You should probably override your onResume() to check if the list of alarms have been refreshed so that whenever you come to/come back to your ListActivity, it'll get updated.

like image 180
corgichu Avatar answered Dec 06 '22 14:12

corgichu


In your alarm list activity

use

public void onRestart() {
    // reload your list items if changed and adapter.notifydatastatechange();
}

If you done this in onResume then its call two times first when your activity start n 2nd when your activity restart.

like image 32
Dhaval Parmar Avatar answered Dec 06 '22 15:12

Dhaval Parmar