android開發人員syncadapter教程是否過期。Android開發者syncadapter教程過時了嗎?
因爲我試圖在我的應用程序中實現同步數據到服務器的同步適配器。但是當執行下面的部分時,我得到了eclipse錯誤。
實現當網絡可用的同步操作的syncadapter:
Android開發教程:
public class MainActivity extends FragmentActivity {
...
// Constants
// Content provider authority
public static final String AUTHORITY = "com.example.android.datasync.provider";
// Account
public static final String ACCOUNT = "default_account";
// Global variables
// A content resolver for accessing the provider
ContentResolver mResolver;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
// Get the content resolver for your app
mResolver = getContentResolver();
// Turn on automatic syncing for the default account and authority
mResolver.setSyncAutomatically(ACCOUNT, AUTHORITY, true);
...
}
...
}
在我的代碼會發生什麼: 有以下變量
// Constants
// The authority for the sync adapter's content provider
public static final String AUTHORITY = "com.example.android.datasync.provider";
// An account type, in the form of a domain name
public static final String ACCOUNT_TYPE = "example.com";
// The account name
public static final String ACCOUNT = "dummyaccount";
// Instance fields
Account mAccount;
// Global variables
// A content resolver for accessing the provider
ContentResolver mResolver;
,並在OnCreate我這樣做:
mAccount = CreateSyncAccount(this);
// Get the content resolver for your app
mResolver = getContentResolver();
// Turn on automatic syncing for the default account and authority
mResolver.setSyncAutomatically(ACCOUNT, AUTHORITY, true);
我在月食中得到一個錯誤mResolver.setSyncAutomatically(ACCOUNT,AUTHORITY,true);它說以下內容:
在類型ContentResolver的方法setSyncAutomatically(帳戶,字符串,布爾)不適用的參數(字符串,字符串,布爾)
,所以我堅持在這裏的教程告訴我這樣做,但ACCOUNT需要是Account類型而不是字符串。教程是否過時?
記錄與谷歌的請求,以便他們可以更新教程,如果你認爲它已過時。這是最好的前進方向。 – ChuongPham