我正在使用SharedPreferences来存储Set
个字符串,使用.putStringSet()
,但我无法使用.getStringSet()
从中获取超过99个项目。
HashSet<String>/Set<String>
是否有尺寸限制?请参阅以下代码:
//Always return 99 items.
private Set<String> getIdentifers(){
Set<String> identifiers = preferences.getStringSet("my_ids", new HashSet<String>());
return new HashSet<String>(identifiers);
}
//`Identifiers` contains 100 items.
private Boolean saveIdentifier(Set<String> identifiers){
SharedPreferences.Editor editor = preferences.edit();
editor.putStringSet("my_ids", identifiers);
return editor.commit();
}
//`Identifiers` show 100 items on Android Studio Debug Console after added `Identifier`to it.
public Boolean addIdentifierToMemory(String identifier){
Set<String>identifiers = getIdentifers(); //99 items
identifiers.add(identifier); //99 items
return savePurchasedProductsIdentifier(identifiers); //100 items
}