zoukankan      html  css  js  c++  java
  • Android为TV端助力 SharedPreferences 轻量级存储!

    首先在当前进程也就是当前的项目里面进行存储

    SharedPreferences.Editor editor = mContext.getSharedPreferences("tvplay", Context.MODE_PRIVATE).edit();
    editor.putString("video", content.getString("video"));
    editor.commit();

    这是存

    SharedPreferences preferences = getTargetContext().getSharedPreferences("tvplay", Context.MODE_PRIVATE);
    video = preferences.getString("video", "");

    这是取

    跨进程SharedPreferences进程存储

    SharedPreferences.Editor editor = mContext.getSharedPreferences("tvplay", Context.MODE_WORLD_READABLE).edit();
    editor.putString("video", content.getString("video"));
    editor.commit();

    这是存跟上面存唯一不同就是模式换了,不懂可以百度!

    private static final String TARGET_PACKAGE_NAME = "com.sdmc.hotel.ollauncher";// 目标数据程序的包名,

    SharedPreferences preferences = getTargetContext().getSharedPreferences("tvplay", Context.MODE_PRIVATE);
    video = preferences.getString("video", "");

    private Context getTargetContext(){
    try {
    return createPackageContext(TARGET_PACKAGE_NAME, Context.CONTEXT_IGNORE_SECURITY);
    } catch (NameNotFoundException e) {
    e.printStackTrace();
    }
    return null;
    }

    这是取,跟上面不同的就是要创建一个你要取的进程的context,然后在调用getSharedPreferences()方法

  • 相关阅读:
    新浪微博爬虫项目
    time
    黑客增长
    python2 3 区别
    爬虫高性能相关
    登录_爬取并筛选拉钩网职位信息_自动提交简历
    破解极验验证码
    tesseract-ocr 传统验证码识别
    刻意练习
    计算学员的考试总成绩以及平均成绩
  • 原文地址:https://www.cnblogs.com/xiaoxiaing/p/5504043.html
Copyright © 2011-2022 走看看