1

私のアプリケーションは、accountmanager を使用してデータを同期しました。認証は使用されません。ときどき (常にではありません)、アプリを初めて実行するときに、最初の同期に時間がかかりすぎます。

ここでアカウントを追加する方法

private void ensureSyncAccount() {
    final AccountManager accountManager = AccountManager.get(this);
    String authority = getString(R.string.acc_authority);
    String accountType = getString(R.string.acc_name);
    String accountName = getString(R.string.app_name);

    Account[] existingAccs = accountManager.getAccountsByType(accountType);
    if (existingAccs.length > 0) {
        return;
    }

    Account account = new Account(accountName, accountType);
    if (accountManager.addAccountExplicitly(account, null, null)) {
        ContentResolver.setIsSyncable(account, authority, 1);
        ContentResolver.setSyncAutomatically(account, authority, true);
        ContentResolver.requestSync(account, authority, new Bundle());
        ContentResolver.addPeriodicSync(account, authority, new Bundle(), 60*10);
    }
    else {
        Log.e(LOG_TAG, "Unable to add account");
    }
}

しばらくすると、同期が正しく機能し始めます。同期のデッドロックの原因は何ですか?

4

1 に答える 1

0

おそらく問題はあなたが requestSync

ContentResolver.requestSync(account, authority, new Bundle());

この後、定期的な同期を追加します

ContentResolver.addPeriodicSync(account, authority, new Bundle(), 60*10);

次の同期を待っています

于 2013-04-30T09:53:09.340 に答える