When a button is pressed the first Fragment retrieves information from a server, in some cases this information takes time due to the bad quality of the links. At the moment of the transition from the first to the second Fragment the screen turns black.
If the link works well and quickly retrieves the information this does not happen.
Is it possible to add a waiting message between fragments?
I add code:
- snip -
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (mItem != null) {
if (mItem.id.equals("1") || mItem.id.equals("2") || mItem.id.equals("6")) {
con = new coneccion(); //Extends DialogFragment
con.conectar(mContexto);
conDeDatos = con.conectado();
if (conDeDatos) {
if (mItem.id.equals("1")) {
rootView = inflater.inflate(R.layout.control_alarma, container, false);
//Enviá comando para recuperar estado svr remoto
enviar(Comandos.OP_ESTADO, "0", "");
//actualiza la vista del fragment
//estado es un array que se llena con cargarEstado(datos)
actualizarAlarma(estado);
}
}
return rootView;
}
- snip -
- snip -
private void enviar(String comando, String accion, String parametro) {
String datos="";
Boolean bandera = false;
con.enviarDatos(comando,accion,parametro);
if(con.sucess()){
try{
datos = con.getData();
}catch(Exception e){
datos = Comandos.RET_ERROR_DESCONOCIDO;
}
Log.v("Data ",datos);
//Si no hay error de claves EK o Error de comando
if(!datos.equals(Comandos.RET_ERROR_COMANDO)
&& !datos.equals(Comandos.RET_ERROR_CLAVES)
&& !datos.equals(Comandos.RET_ERROR_VERSION_PROTO)) {
if (comando.equals(Comandos.OP_ESTADO) || comando.equals(Comandos.OP_ESTADO_LUCES)) { //Estado
bandera = true;
cargarEstado(datos);
}
- snip -
- snip -
private void actualizarAlarma(boolean estado[]){
final Switch swArmar = (Switch) rootView.findViewById(R.id.swArmar);
try {
//estado es que se carga con cargarEstado(datos);
swArmar.setChecked(estado[0]);
}catch(Exception e){
}
swArmar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (swArmar.isChecked()) {
enviar(Comandos.OP_ARMAR,"1","");
} else {
enviar(Comandos.OP_ARMAR,"0","");
}
}
});
- snip -
In onCreateView I establish the connection to svr if we were able to connect it sent a command to be able to synchronize the status.
The sending and receiving is by two AsyncTask methods in the connection class ().
The asynchronous reception task has a time out of at least 5 seconds. In other words, when I send the sync command with the svr, if the response is delayed the screen turns black.
I tried to launch before sending the command and nothing, I also extended the class connection with DialogFragment and nothing. Besides the pre and post Execute and nothing was satisfactory to me, they are all executed when the second fragment is updated. I mean the dialogs or progress bars.