android - 我可以在 Android 同步适配器中使用将由 onperform 同步方法修改的字段变量吗?
问题描述
我有一个 Android Sync 适配器,可以使用 volley 请求将本地数据推送到服务器。我正在使用整数变量 lastid 来检查最后同步的数据行。可以在同步适配器中使用可以通过 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();
}
}
解决方案
推荐阅读
- powershell - PowerShell - 获得今天的获胜活动
- java - 如何在 testcontainers execInContainer 方法中传递命令
- java - 如何在 Apache FOP 中使用 fo:leader?
- python - 负香农熵
- python - Numpy总和搞砸了添加负数
- handlebars.js - 如何使用 bigcommerce 模板组件来处理车把 JS?
- webpack - TypeError:部署到 Vercel 时无法读取 null 的属性“哈希”
- selenium - 如何在 java selenium 中获取谷歌工作表数据?
- r - 有没有办法限制变量以控制多元逻辑回归?
- python - 尝试获取电报聊天 ID 时遇到问题