Могу ли я использовать переменную поля в адаптере синхронизации Android, которая будет изменена методом синхронизации onperform? - PullRequest
0 голосов
/ 30 апреля 2019

У меня есть адаптер Android Sync для отправки локальных данных на сервер с помощью запроса залпа. Я использую целочисленную переменную lastid для проверки последней строки синхронизированных данных. Можно ли использовать переменную в syncadapter, которая может быть изменена методом onPerformSync? влияет ли это на синхронизацию, если адаптер синхронизации обрабатывает запрос parellel? У меня есть случайное отсутствие данных в процессе syc? Может кто-нибудь помочь мне с этим?

public class SyncAdapter extends AbstractThreadedSyncAdapter {

 // Define a variable to contain a content resolver instance
    ContentResolver mContentResolver;
    Context ctx;
    SQLiteDatabase syncdb=null;
    SQLiteDatabase mydbsalesdata=null;
    private String TAG="syncadapter";
    String lastid;

    /**
     * Set up the sync adapter
     */
    public SyncAdapter(Context context, boolean autoInitialize) {
        super(context, autoInitialize);
        ctx=context;
        /*
         * If your app uses a content resolver, get an instance of it
         * from the incoming Context
         */
        mContentResolver = context.getContentResolver();
    }

    /**
     * Set up the sync adapter. This form of the
     * constructor maintains compatibility with Android 3.0
     * and later platform versions
     */
    public SyncAdapter(
            Context context,
            boolean autoInitialize,
            boolean allowParallelSyncs) {
        super(context, autoInitialize, allowParallelSyncs);
        /*
         * If your app uses a content resolver, get an instance of it
         * from the incoming Context
         */
        mContentResolver = context.getContentResolver();

    }

    @Override
    public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {

        /*
         * Put the data transfer code here.
         */

        if(extras!=null){
            if(extras.getString("table")!=null){
                String table=extras.getString("table");

                if(extras.getString("where")!=null){
                    String where =extras.getString("where");
                    if(extras.getString("operation").equalsIgnoreCase("update")){
                        syncUpdate(table,where);
                    }else if(extras.getString("operation").equalsIgnoreCase("delete")){
                        syncDelete(table,where);
                    }
                }else{
                    synctable(table);
                }

            }else if(extras.getString("download")!=null){
                download();
            }else{
                syncperiodic();
            }
        }else{
            syncperiodic();
        }

    }
...