Last Updated: February 25, 2016
·
1.876K
· danielerigo

Show a dialog with all the shared preferences

/** Show a dialog with all the shared preferences */
private void ShowSharedPreferencesDialog(Context mContext) { 
    // Date format
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
    Calendar c = Calendar.getInstance();
    // Retrieve the preferences values
    String message = "SHARED PREFERENCES:\n";
    SharedPreferences shPrefs =  getSharedPreferences("YOUR_KEYWORD", MODE_PRIVATE);
    Map<String,?> keys = shPrefs.getAll();
    for(Map.Entry<String,?> entry : keys.entrySet()){
    message += "["+entry.getKey() + "] " + entry.getValue().toString() + " \n";
    }
    // Show the dialog box
    AlertDialog dialog = new AlertDialog.Builder(mContext).setMessage(message).show();
    TextView textView = (TextView) dialog.findViewById(android.R.id.message);
    textView.setTextSize(12);
}