user4981876 user4981876 - 25 days ago 6
Android Question

Send data to activity with sharedpreferences

Is possible to send data to another activity without starting the activity? And if so is it possible to achieve this with sharedpreferences

Answer Source

Save data in sender Activity:

SharedPreferences prefs = getSharedPreferences(<Name>, <Mode>);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(<KEY>, <VALUE>).commit();
// Save other stuffs here

Extract data in receiver Activity:

SharedPreferences prefs = getSharedPreferences(<Name>, <Mode>);
int value = prefs.getInt(<KEY>, <DEFAULT_VALUE>);