Upon reading the documentation on SharedPreferences edit() carefully, it actually says that the method returns a new editor instance. This means that the following doesnt actually do anything:
prefs.editor().putString("name2","val");
prefs.editor().commit();
Instead, this must be done:
ed.putString("name1","val");
ed.putString("name2","val");
ed.commit();
Or, for single values we can do: