美文网首页
关于SharedPreferences的存储

关于SharedPreferences的存储

作者: 米花噗噗 | 来源:发表于2020-01-10 18:59 被阅读0次

    一。先存储

    SharedPreferences sp = getActivity().getSharedPreferences("con_top", Context.MODE_PRIVATE);

    //获取到edit对象

    SharedPreferences.Editor edit = sp.edit();

    Boolean con_rela_top =true;

    //通过editor对象写入数据

    edit.putBoolean("Value", con_rela_top);

    //提交数据存入到xml文件中

    edit.commit();

    二,获取

    SharedPreferences sp = getActivity().getSharedPreferences("con_top", Context.MODE_PRIVATE);

    //取出数据,

    Boolean value = sp.getBoolean("Value", true);

    if (value ==true) {}

    相关文章

      网友评论

          本文标题:关于SharedPreferences的存储

          本文链接:https://www.haomeiwen.com/subject/mqspactx.html