Well I have the following problem that I think I am in my logic the problem is the following genre a ProgressDialog that at the end or end with the .dismiss () I open or generate another ProgressDialog with the same features I attached the code to a certain extent the functions but there comes a point that becomes an endless loop some idea to make the algorithm more efficient:
public void Export() throws InterruptedException {
final ProgressDialog barProgressDialog = new ProgressDialog(local);
updateBarHandler = new Handler();
barProgressDialog.setTitle("Exportando Datos ...");
barProgressDialog.setCancelable(false);
SQLiteDatabase db = openOrCreateDatabase("db", MODE_PRIVATE, null);
String mqry = "select * from tabla1 WHERE UpdateToServer = 1";
final Cursor crs = db.rawQuery(mqry,null);
int noRegs = crs.getCount();
if(noRegs > 0){
barProgressDialog.setMessage("Enviando datos ...");
barProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
barProgressDialog.setProgress(0);
barProgressDialog.setMax(noRegs);
barProgressDialog.show();
new Thread(new Runnable() {
@Override
public void run() {
try {
while (barProgressDialog.getProgress() <= barProgressDialog.getMax()) {
Thread.sleep(2000);
updateBarHandler.post(new Runnable() {
public void run() {
while (crs.moveToNext()) {
int _i = crs.getInt(crs.getColumnIndex("ID_mov"));
GPro gpro = new GPro();
if (_i == 0) {
gpro.execute(crs.getInt(crs.getColumnIndex("_id")), 1);
} else {
gpro.execute(crs.getInt(crs.getColumnIndex("_id")),2);
}
barProgressDialog.incrementProgressBy(1);
}
}
});
if (barProgressDialog.getProgress() == barProgressDialog.getMax()) {
barProgressDialog.dismiss();
Handler h = new Handler(Looper.getMainLooper());
h.post(new Runnable() {
public void run() {
try {
Export();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
}
}
} catch (Exception ignored) {
Log.e("Registro de Actividad", ignored.toString());
}
}
}).start();
}else{
barProgressDialog.setMessage("No hay Datos que exportar");
barProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
barProgressDialog.show();
new Handler().postDelayed(new Runnable() {
public void run() {
barProgressDialog.dismiss();
try {
ExpoPre();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}, 2000);
}
}