I am adding a set to SharedPreference. This is a static set from another class which processes some data and stores it in the set.
I then move on to another activity (Order Activity) where I display this set's information. The first time when I access the shared preference, I am able to get the correct details. For example name1, name2, name3.
I then leave this activity, go back to another activity, add another name and come back to this Order activity again. I am expecting to get name1, name2, name3, name4 this time. Instead I only get name4. The previous names seems deleted.
Order Activity inside onCreate Method
SharedPreferences prefItemName =
this.getSharedPreferences("com.example..........", MODE_PRIVATE);
//CustomListAdapter is a class that is adding names to the static HashSet names
prefItemName.edit().putStringSet("name", CustomOrderListAdapter.names).apply();
for(String x : prefItemName.getStringSet("name", null)){
Log.i("Name", x);
}
P.S: In the possible duplicate question, he is at least able to store the data all the data as long as he stays logged in. Mine doesn't save as long as I leave the activity. Ist is not the same issue.