I have three activities, A, B & C. Where A is a splash Activity and B Contains Login screen which consist of user Id and Password Text Field and one button to login. When I
to use shared preference in android
public class SharedPref {
public static void setValue(String key, String value, Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(key, value);
editor.commit();
}
public static String getValue(String key, Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
return preferences.getString(key, null);
}
public static void setAlertDialog(Context mContext,String title,String message)
{
AlertDialog alertDialog = new AlertDialog.Builder(mContext).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
}
and to set and get value from the class use following code
SharedPref.setConfig("key","value",Context);
SharedPref.getConfig("key",Context);
SharedPref.setAlertDialog(Context,"title","Content to print");