1

The question is about registering the faculty through android app into the database. When I run the app using the given android emulator it works well, but when run using my personal android devices it generates a TIMEOUT error.

private void registerUser()
{
   final String id=e1.getText().toString().trim();
   final String name=e2.getText().toString().trim();
   final String password=e3.getText().toString().trim();
   final String email=e4.getText().toString().trim();

   //String request
   //use post method in it as it takes values

   progressDialog.setMessage ("Registering User");
   progressDialog.show ();

   StringRequest stringRequest=new StringRequest(Request.Method.POST, Constants.URL_REGISTER,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                    //if there is no error this method will be executed
                        progressDialog.dismiss ();

                        try {
                            JSONObject jsonObject=new JSONObject (response);
                            Toast.makeText (getApplicationContext() ,jsonObject.getString ("message"),Toast.LENGTH_LONG).show ();
                            //jsonObject.getString ("message")
                        }catch (JSONException e){
                            e.printStackTrace ();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        progressDialog.hide ();

                        if(error instanceof NetworkError)
                            Toast.makeText (getApplicationContext (),"Network ERROR",Toast.LENGTH_LONG).show ();

                        if(error instanceof TimeoutError)
                            Toast.makeText (getApplicationContext (),"Time Out ERROR",Toast.LENGTH_LONG).show ();
                        //error.getMessage ()
                        if(error instanceof ServerError)
                            Toast.makeText (getApplicationContext (),"Server ERROR",Toast.LENGTH_LONG).show ();


                    }
                }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String> params=new HashMap<> ();
                params.put("Faculty_ID",id);
                params.put("Faculty_Name",name);
                params.put("Faculty_Password",password);
                params.put("Faculty_Email",email);
                return params;
            }
      };

     //RequestQueue requestQueue= Volley.newRequestQueue(this);
     //requestQueue.add(stringRequest);
     //    finish ();
     RequestHandler.getInstance (this).addToRequestQueue (stringRequest);
 }    

Used phpmyadmin. It only gives a timeout error */

Thanks

Pom12
  • 7,622
  • 5
  • 50
  • 69

1 Answers1

0

Set a retry policy in case of SocketTimeout & ConnectionTimeout Exceptions. Volley does retry for you if you have specified the policy.

stringRequest.setRetryPolicy(new DefaultRetryPolicy(5000, 
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

For more details click here

Dhanumjay
  • 540
  • 7
  • 17