Android studio 改造android studio时出现异步响应问题

Android studio 改造android studio时出现异步响应问题,android-studio,retrofit,Android Studio,Retrofit,我正在使用android studio进行改造,并向服务器发出多个请求。我想知道哪些请求对应于哪些响应,因为这取决于我删除一个元素还是另一个元素。 我的申请代码如下: ConexionSQLiteHelper conexionSQLiteHelper = new ConexionSQLiteHelper(context, NOMBRE_BD, null, 1); SQLiteDatabase dbread = conexionSQLiteHelper.getReadabl

我正在使用android studio进行改造,并向服务器发出多个请求。我想知道哪些请求对应于哪些响应,因为这取决于我删除一个元素还是另一个元素。 我的申请代码如下:

ConexionSQLiteHelper conexionSQLiteHelper = new ConexionSQLiteHelper(context, NOMBRE_BD, null, 1);
            SQLiteDatabase dbread = conexionSQLiteHelper.getReadableDatabase();
            Cursor c = dbread.rawQuery(COMRPUEBA_SYNC, new String[] {username});

            SQLiteDatabase dbwrite = conexionSQLiteHelper.getWritableDatabase();

            // Si hay conexión a internet y hay datos en SQLite, sincronizamos.
            if(c.getCount() > 0){
                if (c.moveToFirst()){
                    while(!c.isAfterLast()){
                        trafficSign = new TrafficSign(c.getInt(c.getColumnIndex(CAMPO_ID)),
                                c.getDouble(c.getColumnIndex(CAMPO_LONGITUD)),
                                c.getDouble(c.getColumnIndex(CAMPO_LATITUD)),
                                c.getDouble(c.getColumnIndex(CAMPO_ANCHO)),
                                c.getDouble(c.getColumnIndex(CAMPO_ALTO)),
                                c.getString(c.getColumnIndex(CAMPO_CLASE)),
                                c.getString(c.getColumnIndex(CAMPO_USERNAME)));
                        // Registramos en el servidor.
                        Retrofit retrofit = new Retrofit.Builder().baseUrl(url)
                                .addConverterFactory(GsonConverterFactory.create())
                                .build();
                        Service service = retrofit.create(Service.class);
                        Call<ResponseBody> call = service.saveDetection(sessionid, trafficSign);
                        call.enqueue(new Callback<ResponseBody>() {
                            @Override
                            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                                new Gson().toJson(response.raw().request().body());
                                Log.d(TAG, "Señal "+trafficSign.getId()+" sincronizada con servidor. Code: "+ response.code());
                                // La eliminamos de la base de datos local
                                dbwrite.execSQL(BORRA_SINCRONIZADOS, new String[]{""+trafficSign.getId()});
                                c.close();
                            }

                            @Override
                            public void onFailure(Call<ResponseBody> call, Throwable t) {
                                Log.d(TAG, "Señal "+trafficSign.getId()+" no se ha podido sincronizar con el servidor. Message: "+t.getMessage());
                                c.close();
                            }
                        });

                    c.moveToNext();
                    }
                }
            }else{
                Log.wtf(TAG, "Bases de datos sincronizadas.");
            }
ConexionSQLiteHelper ConexionSQLiteHelper=new-ConexionSQLiteHelper(context,NOMBRE_BD,null,1);
SQLiteDatabase dbread=conexionSQLiteHelper.getReadableDatabase();
游标c=dbread.rawQuery(COMRPUEBA_同步,新字符串[]{username});
SQLiteDatabase dbwrite=conexionSQLiteHelper.getWritableDatabase();
//Si hay conexión a互联网和SQLite的hay datos,sincronizamos。
如果(c.getCount()>0){
if(c.moveToFirst()){
而(!c.isAfterLast()){
交通标志=新交通标志(c.getInt(c.getColumnIndex(CAMPO_ID)),
c、 getDouble(c.getColumnIndex(CAMPO_LONGITUD)),
c、 getDouble(c.getColumnIndex(CAMPO_LATITUD)),
c、 getDouble(c.getColumnIndex(CAMPO_ANCHO)),
c、 getDouble(c.getColumnIndex(CAMPO_ALTO)),
c、 getString(c.getColumnIndex(CAMPO_CLASE)),
c、 getString(c.getColumnIndex(CAMPO_用户名));
//我是塞维多尔。
改装改装=新建改装.Builder().baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.build();
服务=改装.create(服务.class);
Call Call=service.saveDetection(sessionid,trafficSign);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
新的Gson().toJson(response.raw().request().body());
Log.d(标记“Señal”+trafficSign.getId()+“sincronizada con servicedor.Code:”+response.Code());
//当地达托斯基地酒店
execSQL(BORRA_SINCRONIZADOS,新字符串[]{”“+trafficSign.getId()});
c、 close();
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
Log.d(标记“Señal”+trafficSign.getId()+“no Se ha podido sincronizar con el servicdor.Message:”+t.getMessage());
c、 close();
}
});
c、 moveToNext();
}
}
}否则{
wtf(标签“Bases de datos sincronizadas.”);
}
@POST(“检测”)
调用保存检测(@Header(“Cookie”)字符串sessionid,@Body TrafficSign TrafficSign);

问题是,当响应到达时,SQLite数据库中的指针已经移动到末尾,因此最后一项是唯一要删除的项。

听起来您可能需要修改REST服务以包含id或序列?
@POST("deteccion")
    Call<ResponseBody> saveDetection(@Header("Cookie") String sessionid, @Body TrafficSign trafficSign);