I have a button on an action bar that reflects how many items are in the user's favourites. How can I get this to refresh when the back button is pressed?
Asked
Active
Viewed 941 times
0
-
use onbackkeypressed method. – Avijit Feb 05 '14 at 12:11
-
possible duplicate of [Android - How To Override the "Back" button so it doesn't Finish() my Activity?](http://stackoverflow.com/questions/3141996/android-how-to-override-the-back-button-so-it-doesnt-finish-my-activity) – DroidDev Feb 05 '14 at 12:15
2 Answers
4
try this.
@Override
public void onResume() {
invalidateOptionsMenu();
}

John
- 8,846
- 8
- 50
- 85
-
replace invalidateOptionsMenu(); with supportInvalidateOptionsMenu(); if you are using actionbarsherlock – user3225075 Aug 27 '15 at 03:50
0
Use this:
@Override
public void onBackPressed() {
//Refresh action bar
}

SoulRayder
- 5,072
- 6
- 47
- 93
-
That only fires on the current activity? How can I make the activity the user is navigating back to refresh the action bar? – user2610744 Feb 05 '14 at 12:15
-
Set some common variable (global) between the two activities. In this onBackPressed() just set that value. Later when you go back to the other activity, check for this value and then refresh action bar. – SoulRayder Feb 05 '14 at 12:17