我有一个Android Sync适配器,可以使用截击请求将本地数据推送到服务器。我正在使用整数变量lastid来检查该最后同步的数据行。在syncadapter中使用可以由onPerformSync方法修改的变量可以吗?如果同步适配器正在处理并行请求,是否会影响同步?我在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();
}
}