I am first in Android (Java) and I want to get the request response by blocking the user screen with a Progressbar while it ends.
Intent intent= new Intent(iniciarSesion.this, MainActivity.class);
intent.putExtra("id",id);
intent.putExtra("nom_usu",nom_usu);
intent.putExtra("equipo",equipo);
intent.putExtra("password",password);
startActivity(intent);
if (equipo.equals("S")) {
añadirequipo x = new añadirequipo();
x.nombreCancha(id,getApplicationContext()); }
public void nombreCancha(String idUsuario,Context mContext) {
String URL="url"+idUsuario+"";
JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(URL, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
JSONObject jsonObject = null;
for (int i = 0; i < response.length(); i++) {
try {
jsonObject = response.getJSONObject(i);
id_equipo = jsonObject.getString("idequipo");
id_usu = jsonObject.getString("idusuario");
nombre_equipo = jsonObject.getString("nombre_equipo");
cancha = jsonObject.getString("cancha");
} catch (JSONException e) {
Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.v("Fallo_Json:", e.getMessage());
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (error.toString().equals("com.android.volley.ParseError: org.json.JSONException: Value null of type org.json.JSONObject$1 cannot be converted to JSONArray")){
Toast.makeText(mContext, "No existe ese usuario", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(mContext, "Fallo json"+error.getMessage(), Toast.LENGTH_SHORT).show();
Log.v ("Fallo_Listener:", error.getMessage());
}
}
}
);
requestQueue= Volley.newRequestQueue(mContext);
requestQueue.add(jsonArrayRequest);
}
The nombreCancha method sets a String field variable that is then retrieved in a fragment
public String esperarNombre() {
return cancha;
}
What happens is that before the fragment of the response is finished, I want the application to stop while the response is over and place a Progressbar while it ends.
I know that the Request an async thread and I don't want to do it sync I want the application to wait for that to end that with a loading bar.
Note 1:
Hello
Toast.makeText(getApplicationContext(), "Bienvenido "+nom_usu+" ", Toast.LENGTH_SHORT).show();
Intent intent= new Intent(iniciarSesion.this, MainActivity.class);
intent.putExtra("id",id);
intent.putExtra("nom_usu",nom_usu);
intent.putExtra("equipo",equipo);
intent.putExtra("password",password);
startActivity(intent);
if (equipo.equals("S")) {
loader.setVisibility(VISIBLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
añadirequipo x = new añadirequipo();
x.nombreCancha(id,getApplicationContext(),loader);
}
public void onResponse(JSONArray response) {
JSONObject jsonObject = null;
for (int i = 0; i < response.length(); i++) {
try {
jsonObject = response.getJSONObject(i);
id_equipo = jsonObject.getString("idequipo");
id_usu = jsonObject.getString("idusuario");
nombre_equipo = jsonObject.getString("nombre_equipo");
cancha = jsonObject.getString("cancha");
} catch (JSONException e) {
Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.v("Fallo_Json:", e.getMessage());
}
}
// progressDialog.dismiss();
loader.setVisibility(GONE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
give my a error : Attempt to invoke virtual method 'void android.view.Window.clearFlags(int)' on a null object reference