You need to use SharedPreferences . To save data even after closing the application, and you can access it from anywhere:
public void savePrefrences(String key, String value) { SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), 0); prefs.edit().putString(key, value).commit(); } public String getPrefrences(String key) { SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), 0); return prefs.getString(key, ""); }
Maintain your advantage whenever and wherever you want, and get it whenever you want.
The value will not be deleted when the application is closed.
source share