zoukankan      html  css  js  c++  java
  • 多个APK之间简单数据共享

    在APK的manifest节点中保证其  android:sharedUserId="hello.miles"  保持一致,名称可以自定义

    // 创建共享数据的APK  其manifest包名为com.miles.sharedata
    SharedPreferences sp = Context.getSharedPreferences(String name, int mode)
    Editor editor = sp.edit()
    // 存值
    editor.putBoolean("share1", true);
    editor.putInt("share2", 10);
    ...
    editor.commit();
    PS:要其他APK能够读取或者修改这里的数据
    其mode指定为Context.MODE_WORLD_READABLE或者Context.MODE_WORLD_WRITEABLE
    // 读取共享数据的APK
    Context context = Context.createPackageContext("com.miles.sharedata", Context.CONTEXT_IGNORE_SECURITY);
    SharedPreferences preferences = context.getSharedPreferences(String name, int mode );
    // 取值操作
    boolean share1 = preferences.getBoolean("share1",  false);
    int share2 = preferences.getInt("share2",  0);
    ...
  • 相关阅读:
    4.20 每日一练
    4.19 每日一练
    4.18 每日一练
    Python函数初
    Python的文件操作
    python购物车
    python深浅拷贝,集合以及数据类型的补充
    Python 代码块 小数据池
    Python字典
    Python 列表操作
  • 原文地址:https://www.cnblogs.com/smile365/p/3709370.html
Copyright © 2011-2022 走看看