Skip to content

ContentProvider配合SharePrefrence解决多进程/跨进程数据共享问题

Notifications You must be signed in to change notification settings

LongAgoLong/RemoteSPHelp

Repository files navigation

SharePreference&ContentProvider跨进程数据存储与共享


Server服务端实现

①在project的build.gradle文件中添加url

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

②在module的build.gradle文件中添加依赖

implementation "com.github.LongAgoLong.RemoteSPHelp:provider:$Tag"

③AndroidManifest.xml文件中添加以下代码

<meta-data
    android:name="authority"
    android:value="com.android.sp.provider" />

<provider
    android:name="com.leo.sp.provider.SPContentProvider"
    android:authorities="com.android.sp.provider"
    android:exported="true"
    android:grantUriPermissions="true" />
  • authorityvalue值等同于provider标签中的android:authorities属性;

Client客户端实现

①在project的build.gradle文件中添加url

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

②在module的build.gradle文件中添加依赖

implementation "com.github.LongAgoLong.RemoteSPHelp:resolver:$Tag"

③AndroidManifest.xml文件中添加以下代码

<queries>
    <package android:name="com.leo.remotesphelp" />
</queries>

<meta-data
    android:name="authority"
    android:value="com.android.sp.provider" />
  • value必须与server客户端中定义的authorities相同

④在Application onCreate()方法中调用以下方法初始化

@Override
public void onCreate() {
    super.onCreate();
    SpContants.initAuthority(this);
    SpResolver.getInstance().init(this);
}

About

ContentProvider配合SharePrefrence解决多进程/跨进程数据共享问题

Resources

Stars

Watchers

Forks

Packages

No packages published