So I have some shared preferences in my main activity:
SharedPreferences prefs = this.getSharedPreferences("myFavs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
And I add some generated strings as a key value pair:
editor.putString(saved,saved);
editor.apply();
In another activity I would like to be able to display all the key value pairs I have saved in my shared preferences file into a ListView.
I have used things like:
ListView listView = (ListView) findViewById(R.id.favsList);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.listlayout, android.R.id.text1, values );
listView.setAdapter(adapter);
before, however I am not sure how to get all my shared preferences into a format that I can put into a ListView.
P.S I should have mentioned I only really need a list of either keys or values as the key and the value are always the same.
I think this might have solved my problem:
SharedPreferences prefs = getSharedPreferences("myFavs", 0);
Map<String, String> m = (Map<String, String>) prefs.getAll();
List<String> list = new ArrayList<>(m.values());
Is this correct?