[英]What is the best way to store a set of strings
So I have a set of strings: 所以我有一组字符串:
public Set<String> favs = new HashSet<>();
Which I add to in the activity later. 我稍后会在活动中添加。 However I want to be able to read and write these strings from other activities using just one source for all the data I've added a little graphic to try and explain what I mean better. 但是,我希望能够仅使用一个源来读取和写入其他活动中的这些字符串,而我添加了一些图形来尝试解释我的意思。 What would be the best way to store my individual strings in this manner? 以这种方式存储我的单个字符串的最佳方法是什么?
I would want the data to persist on closing the app. 我希望数据在关闭应用程序时保持不变。 At a guess there would be a maximum of about 30 items. 大概最多会有30个项目。 The data would come internally from entered data. 数据将在内部来自输入的数据。
consider using shared preference. 考虑使用共享首选项。
public void setValue(Set<String> stringSet) {
getSharedPreferences(getClass().getSimpleName(), Context.MODE_PRIVATE).edit().putStringSet("key",stringSet).comit();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.