rincEwind
rincEwind

Reputation: 183

Store simple application data on Android

My activity allows the user to select multiple folders. I would like to store this selection in order to be able to recreate it later (ie. mark folders as selected when the activity is started again). What's the best approach to do this? I'm thinking of using Shared Preferences or Internal Storage (write a file with paths list when activity finishes and read this file on activity start).

Upvotes: 0

Views: 66

Answers (1)

M-Wajeeh
M-Wajeeh

Reputation: 17304

User SharedPreferences:

SharedPreferences sp = PreferenceManager
                    .getDefaultSharedPreferences(getActivity());
Editor editor = sp.edit();
editor.putStringSet("selectedFolders", selectedFolders);
editor.commit();

to get it later:

SharedPreferences sp = PreferenceManager
                    .getDefaultSharedPreferences(getActivity());
Set<String> selectedFolders = sp.getStringSet("selectedFolders", new HashSet<String>()):

Upvotes: 1

Related Questions