The World’s Largest Online Community for Developers

'; android - SyncAdapter onPerformSync does not get called - LavOzs.Com

I am developing an offline-first app that uses a SyncAdapter to load the data to a webserver. Basically, the data is saved to a local SQLite database using greenDao library. Everytime data is added or deleted, I call the performSync() method so it gets synced with the webserver. My problem is, that onPerformSync() never gets called.

I am new to this concept and am still learning, so there are a few things that are not clear to me.

I have implemented StubAuthenticator, StubAuthenticatorService, StubProvider, SyncAdapter and SyncService as it is done in the documentation.

I was not clear about the accountType. In the documentation, they say:

The sync adapter framework requires each sync adapter to have an account type, in the form of a domain name. The framework uses the account type as part of the sync adapter's internal identification. For servers that require login, the account type along with a user account is sent to the server as part of the login credentials. If your server doesn't require login, you still have to provide an account type. For the value, use a domain name that you control. While the framework uses it to manage your sync adapter, the value is not sent to your server.

My server does not require login, but i am not sure what to pass to the accountType attribute.

Repository class for database functions:

public class UnicornRepository {

    private static String AUTHORITY = ".sync";
    private static String ACCOUNT = "dummyAccount";
    private static String ACCOUNT_TYPE = ""; //Not sure about this

    private static UnicornRepository instance;

    private Account mAccount;

    private UnicornRepository(Context application){
        mAccount = createSyncAccount(application);

    public static UnicornRepository getInstance(Context application) {
        if (instance == null) {
            instance = new UnicornRepository(application);
        return instance;

    public void addUnicorn(Unicorn unicorn) {
        //Add unicorn to database

    public void deleteUnicorn(Unicorn unicorn) {
        //Delete unicorn from database

    private Account createSyncAccount(Context context) {
        Account account = new Account(ACCOUNT, ACCOUNT_TYPE);
        AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
        accountManager.addAccountExplicitly(account, null, null); //returns false
        return account;

    private void sync() {
        ContentResolver.requestSync(mAccount, AUTHORITY, Bundle.EMPTY);

accountManager.addAccountExplicitly() returns false, so the account can't get logged in. Is that the reasen onPerformSync() does not get called? If yes, what should i pass to accountType?

I am not sure if that is enough information. If you need some more infos, I can add them.

EDIT: I just found out that the account gets logged in, so this is not the problem. The problem has to be somewhere else.

How to get screen dimensions as pixels in Android
Android SyncAdapter use case
How do I implement an Account on Android without a SyncAdapter
How to handle RESTful update of remote server with SyncAdapter
SyncAdapter Without an Account
How is a SyncAdapter triggered by the system?
Android Syncadapter not let user choose to sync or not sync
Android developers syncadapter tutorial out of date?
SyncAdapters.requestSync and Android SyncManager
Android:ContentResolver.requestSync() is not triggering onPerformSync()