0
すべてのsqliteデータをサーバに同期したいと思います。すべてが魅力のように働いていますが、私のProgressDialog
は、すべてのデータがサーバーに同期するまで表示されません。同期ボタンを押すと、すべてのデータがサーバーに正常に保存されますが、すべてのデータが同期されるまでProgressDialog
が表示されません。SQLiteからデータを同期しているときにProgressDialogをAsyncTaskに表示する方法は?
//TO call web service save Data on Server
class async_SaveData extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog();
}
@Override
protected String doInBackground(String... params) {
SoapObject request = new SoapObject(namespacegetlistdata, method_name__getlistdata);
cursor = db.rawQuery("select * from FieldTestDataFinal Where isSend ='N' and ProjectId = '" + gp.number + "'", null);
/*for(int i=0; i<cursor.getCount(); i++)
{*/
int k = 0;
try {
if (cursor.moveToFirst()) {
/*while (cursor.moveToNext())*/
do {
JSONArray arr = new JSONArray();
JSONObject jsonObject = new JSONObject();
jsonObject.put("ConsAcNo", cursor.getString(cursor.getColumnIndex("CONS_ACCOUNT_NO")));
jsonObject.put("MeterSrNo", cursor.getString(cursor.getColumnIndex("MTR_SERIAL_NO")));
jsonObject.put("KNoNumber", cursor.getString(cursor.getColumnIndex("KNO_NO")));
//request.properties.clear();
if (k == 0) {
request.addProperty(parameter_getlistdata, jsonObject.toString());//add the parameters
request.addProperty(parameter_getlistdata1, "XXMFU_APP_INSERTFIELDDATA");//add the parameters
} else {
request.setProperty(0, jsonObject.toString());//add the parameters
request.setProperty(1, "XXMFU_APP_INSERTFIELDDATA");//add the parameters
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);//set soap version
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(url_getlistdata);
androidHttpTransport.call(soap_action_getlistdata, envelope); // this is the actual part that will call the webservice
//SoapPrimitive prim = (SoapPrimitive) envelope.getResponse(); // Get the SoapResult from the envelope body.
SoapObject response = (SoapObject) envelope.bodyIn;
} catch (Exception e) {
e.printStackTrace();
Log.d("myError -", String.valueOf(e));
}
k++;
} while (cursor.moveToNext());
}
cursor.close();
} catch (Exception e) {
}
// }
return resultSaveAllData;
}
@Override
protected void onPostExecute(String result1) {
new async_SaveImage().execute();
super.onPostExecute(result1);
}
}
//TO call web service save Image on Server
class async_SaveImage extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
SoapObject request = new SoapObject(namespacegetlistdata, method_name__image);
cursorImage = db.rawQuery("select * from FieldTestDataFinal Where isSend ='N' and ProjectId = '" + gp.number + "'", null);
/*for(int i=0; i<cursor.getCount(); i++)
{*/
int k = 0;
try {
if (cursorImage.moveToFirst()) {
/*while (cursor.moveToNext())*/
do {
//request.properties.clear();
if (k == 0) {
request.addProperty("fileByte1", cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE1")));//add the parameters
request.addProperty("fileName1", cursorImage.getString(cursorImage.getColumnIndex("fileName1")));//add the parameters
request.addProperty("fileByte2", cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE2")));//add the parameters
request.addProperty("fileName2", cursorImage.getString(cursorImage.getColumnIndex("fileName2")));//add the parameters
request.addProperty("fileByte3", cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE3")));//add the parameters
request.addProperty("fileName3", cursorImage.getString(cursorImage.getColumnIndex("fileName3")));//add the parameters
request.addProperty("fileByte4", cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE4")));//add the parameters
request.addProperty("fileName4", cursorImage.getString(cursorImage.getColumnIndex("fileName4")));//add the parameters
request.addProperty("fileByte5", cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE5")));//add the parameters
request.addProperty("fileName5", cursorImage.getString(cursorImage.getColumnIndex("fileName5")));//add the parameters
request.addProperty("fileByte6", cursorImage.getString(cursorImage.getColumnIndex("SIGNATURE_CONSUMER")));//add the parameters
request.addProperty("fileName6", cursorImage.getString(cursorImage.getColumnIndex("fileName6")));//add the parameters
// request.addProperty("fileName", "123.jpeg");//add the parametershe parameters
} else {
request.setProperty(0, cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE1")));//add the parameters
request.setProperty(1, cursorImage.getString(cursorImage.getColumnIndex("fileName1")));//add the parameters
request.setProperty(2, cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE2")));//add the parameters
request.setProperty(3, cursorImage.getString(cursorImage.getColumnIndex("fileName2")));//add the parameters
request.setProperty(4, cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE3")));//add the parameters
request.setProperty(5, cursorImage.getString(cursorImage.getColumnIndex("fileName3")));//add the parameters
request.setProperty(6, cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE4")));//add the parameters
request.setProperty(7, cursorImage.getString(cursorImage.getColumnIndex("fileName4")));//add the parameters
request.setProperty(8, cursorImage.getString(cursorImage.getColumnIndex("METER_IMAGE5")));//add the parameters
request.setProperty(9, cursorImage.getString(cursorImage.getColumnIndex("fileName5")));//add the parameters
request.setProperty(10, cursorImage.getString(cursorImage.getColumnIndex("SIGNATURE_CONSUMER")));//add the parameters
request.setProperty(11, cursorImage.getString(cursorImage.getColumnIndex("fileName6")));//add the parameters
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);//set soap version
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(url_getlistdata);
androidHttpTransport.call(soap_action_uploadImage, envelope); // this is the actual part that will call the webservice
//SoapPrimitive prim = (SoapPrimitive) envelope.getResponse(); // Get the SoapResult from the envelope body.
SoapObject response = (SoapObject) envelope.bodyIn;
} catch (Exception e) {
e.printStackTrace();
Log.d("myError -", String.valueOf(e));
}
k++;
} while (cursorImage.moveToNext());
}
cursorImage.close();
} catch (Exception e) {
}
// }
return resultSaveAllData;
}
@Override
protected void onPostExecute(String result1) {
//db.execSQL("UPDATE FieldTestDataFinal SET isSend='Y' WHERE isSend='N' and ProjectId = '"+gp.number+"'");
hideDialog();
Toast.makeText(DashBoardActivity.this, "Records synced with server", Toast.LENGTH_LONG).show();
super.onPostExecute(result1);
}
}
// this is used to show diologue
private static void showDialog() {
if (!pDialog.isShowing())
pDialog.show();
}
// this is used to hide diologue
public static void hideDialog() {
if (pDialog.isShowing())
pDialog.dismiss();
}
を?私は間違って何かしていますか? –
'publishProgress'と' onProgressUpdate(Integer ...)を使用してください ' – Vyacheslav
@MoinKhan、更新 – Vyacheslav