zoukankan      html  css  js  c++  java
  • 冲刺六

    今天是冲刺的第六天,主要学习了安卓永久性储存和读取用户ID。

    遇到的困难:暂无。

    解决思路:利用上下问获取一个SharedPreferences对象,进而对用户ID进行储存和访问。

    明天计划完成的任务:实现用户的收藏

    附上编写的代码:

    StoreId.java

    package com.itheima.cloudnotes.store;
    
    import android.content.Context;
    import android.content.SharedPreferences;
    
    import static android.content.Context.MODE_PRIVATE;
    
    public class StoreId
    {
        private  Context context;
        public StoreId(Context context)
        {
            this.context=context;
        }
    
        public void WiteId(int id)
        {
            SharedPreferences.Editor editor    =context.getSharedPreferences("user_id",MODE_PRIVATE).edit();
            editor.putInt("userId",id);
            editor.apply();
        }
    
        public void ReadId()
        {
            SharedPreferences pref=    context.getSharedPreferences("user_id",    MODE_PRIVATE);
            int    userId    =    pref.getInt("userId",0);
        }
    
    }
  • 相关阅读:
    获取本地地址,获取上传文件的后缀
    foreach
    es6入门
    jquery-ui 拖拽排序
    移动端常用
    vue父子组件通信
    Weinre(pc调试手机页面)
    Ztree的使用
    jquery on() 转
    c++ 基本使用
  • 原文地址:https://www.cnblogs.com/weixiao1717/p/13084580.html
Copyright © 2011-2022 走看看