SharedPreferences getString NULL 参数

编程入门 行业动态 更新时间:2024-10-24 04:47:22
本文介绍了SharedPreferences getString NULL 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我将 SharedPreferences.getString 的第二个参数设置为 NULL,我会在某些设备上收到错误(异常)吗?

Will I receive an error (Exception) on some devices if I set the second parameter of SharedPreferences.getString NULL?

SharedPreferences settings = ... String data = settings.getString(_.PREFIX , null);

它是否会导致至少一台设备出现异常或错误?或者我必须将这部分代码包装在 try-catch 块中?

Will it cause an exception or an error on at least one device? Or I have to wrap this part of code in try-catch block?

推荐答案

String data = settings.getString(_.PREFIX , null/Null here is default value/);null - 当您的 SraredPreferences 没有此项目时,您可以接收(例如,如果您在将此字段设置为任何信息或用户从设备设置中清除应用程序现金之前调用/获取此字符串).我认为这可能是正常情况,如果您希望得到它(一些 emum 字段),您可以使用一些默认值删除null".如果您不认为在使用前获取空验证数据.我认为您的应用程序必须准备好获得两种变体,因为用户可以更改正常工作流程.

String data = settings.getString(_.PREFIX , null/Null here is default value/); null - u can receive when your SraredPreferences have not this item(For example if u call/get this string before setting to this field any info or user clear cash of application from settings of device). I think it's can be normal situation, and u can remove "null" with some default value if you hope to got it(some emum field). If u don't suppose get null validate data before using. I thin'k your app must be ready get both variant, because user can change normal workflow.

更多推荐

SharedPreferences getString NULL 参数

本文发布于:2023-11-10 06:26:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574603.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   SharedPreferences   getString   NULL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!