共享首选项-单个值的最大长度 [英] Shared Preferences - max length of a single value

查看:69
本文介绍了共享首选项-单个值的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将String存储到共享的首选项中,但是我无法找出可以存储的最大字符串长度.你知道这个值吗?

I am storing String into shared preferences, but I wasn't able to find out maximal length of string I can store. Do you know this value?

推荐答案

通过 Romain Guy 从问题在这里问

Java字符串的最大长度是多少.所以像 整数.MAX_VALUE个字符.

Whatever the maximum length of a Java string is. So something like Integer.MAX_VALUE chars.

我想,如果SharedPreference是一个XML文件,并且如果您仅存储一对/对象,则该XML文件将与一个标签一起存储. 因此,如果您认为自己正在写文件,则写String是没有限制的.(理论上)

I suppose while SharedPreference is an XML file stored with One Tag if you store only One Pair/Object. So there is no limit to write String in that if you think like you are writing in a file..(Theoretically)

但是实际上发生的是,当您当时使用put/get函数将值分配给SharedPreference 时,在字符串对象中读取/写入值 .. so,因此限制可以一次存储等于Java字符串对象的大小限制的值.

But Actually what happens is that, while you are assigning value to SharedPreference using put/get function at that time you Reading/Writting value in String Object..so the limit becomes to store value at one time equal to Size limit of String Object of Java.

因此,在编写代码时: Limited of SharedPreference字符串大小= Java字符串对象大小限制(实际上)

So while writting the code: Limit of SharedPreference String Size = Java String Object Size Limit(Practically)

这篇关于共享首选项-单个值的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆