Android : Dialog and Asynctaks behaviour

on Tuesday, February 17, 2015


I have a doubt with the behaviour of an Asynctask with a Dialog that I'm doing. Basically I have a field in my preferences. If it's true I must show a Dialog with 3 fields fill them and after that I append this info into a file that I have and send it through FTP. If it's false I send directly my File using FTP.



public void altaAction(View view){

if(checkFields()){
if(prefs.getBoolean("myOption", false))
createPartidaDialog();
//Here I prepare my file with some info
altArtFile.add(...);
...
...
...

//If my option is false I send my file
if(!prefs.getBoolean("myOption",false))
new AsyncSender().execute(altaArtFile);
}


private void createPartidaDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(AltaArtActivity.this);
alertDialog.setTitle("Partida");
alertDialog.setMessage("Inserta Datos Partida");

LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);

final EditText cajasInput = new EditText(this);
cajasInput.setHint("Cajas");
cajasInput.setSingleLine(true);
cajasInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
cajasInput.setInputType(InputType.TYPE_CLASS_NUMBER);
layout.addView(cajasInput);

final EditText kilosInput = new EditText(this);
kilosInput.setHint("Kilos");
kilosInput.setSingleLine(true);
kilosInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
kilosInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

layout.addView(kilosInput);

final EditText precioInput = new EditText(this);
precioInput.setHint("Precio");
precioInput.setSingleLine(true);
precioInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
precioInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
layout.addView(precioInput);
alertDialog.setView(layout);

alertDialog.setPositiveButton("Aceptar",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
try{
//Append the info to existing file
altaArtFile.add(info);
altaArtFile.add(info);
altaArtFile.add(info);

//Send my file with AsyncSender
new AsyncSender().execute(altaArtFile);
dialog.dismiss();
AltaArtActivity.this.finish();
}catch(SQLException e){
e.printStackTrace();
}
}
});

alertDialog.setNegativeButton("Cancelar",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});

alertDialog.show();


The problem that I'm getting is that my FTP Server gets my file twice, like If I were calling twice Asyncsender and I don't know why this is happening. Maybe this is not a well designed solution. Any help would be so appreciated. Thank you very much


0 comments:

Post a Comment