performSync()正在为Android 7以下工作。对于Android 7及更高版本的顺序(队列)不一样。
同步适配器配置如下。
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/account_type"
android:allowParallelSyncs="false"
android:contentAuthority="@string/authority"
android:isAlwaysSyncable="true"
android:supportsUploading="true"
android:userVisible="false" />
authenticator.xml如下所示
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/account_type"
android:icon="@mipmap/ic_launcher"
android:label="@string/label"
android:smallIcon="@mipmap/ic_launcher" />
用于手动同步的代码如下。
private void requestSync(Account account, PersonDto personDto) {
Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); // Performing a sync no matter if it's off
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); // Performing a sync no matter if it's off
bundle.putString("SYNC_TYPE", "SendPerson");
ContentResolver.requestSync(account, ReferenceCodeContentProvider.AUTHORITY, bundle);
}
ApplicationSyncAdapter代码如下
public class ApplicationSyncAdapter extends AbstractThreadedSyncAdapter {
private static final String TAG = "ApplicationSyncAdapter";
private final AccountManager mAccountManager;
public ApplicationSyncAdapter(Context context, boolean autoInitialize) {
super(context, autoInitialize);
mAccountManager = AccountManager.get(context);
}
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
ContentProviderClient provider, SyncResult syncResult) {
String syncType = extras.getString("SYNC_TYPE");
if (syncType.equals("SendPerson")) {
}
}
我在离线(无网络)的5人循环中调用requestSync()方法 它在7以下的android工作正常。即当网络回来时。 performSync()按顺序调用(p1,p2,p3,p4,p5)
但是对于Android 7及更高版本,我在for循环中的顺序与performSync()方法中的顺序不同。即,performSync()方法调用随机顺序。 (p3,p2,p4,p1,p5)
我的代码有问题吗?