I have a menu in an Android application, and when I click one of the buttons to start a new activity I want the instance variables to keep their values even if I go back to the menu and start it again.
This is what I’ve tried:
public void onClick(View v) {
Bundle b = new Bundle();
b.putBoolean("isFav",false);
centralsIntent = new Intent("kth.blod.CENTRALS");
centralsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
centralsIntent.putExtras(b);
startActivity(centralsIntent);
}
And in the manifest:
android:launchMode="singleTop"
I think shared preferences are the easiest way to keep track of values you have set in one part of your application that you want to save and possibly modify upon returning from another part of the application. See this link for Shared Preferences. See this link to see how to implement them. Good luck!