2016-11-04 11 views
0

これは2回実行されます。一度だけ実行する必要があります。私はAndroid Volley Double Post

_urlWebService = vars.ipServer.concat("/ws/disponibilidadTicket");

JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, _urlWebService, null, 
     new Response.Listener<JSONObject>() 
     { 
      @Override 
      public void onResponse(JSONObject response) 
      { 
       try 
       { 
        JSONArray clientes; 

        if(response.getBoolean("status")) 
        { 


        } 

       } 
       catch (JSONException e) 
       { 
        e.printStackTrace(); 
       } 
      } 
     }, 

     new Response.ErrorListener() 
     { 
      @Override 
      public void onErrorResponse(VolleyError error) 
      { 

       if (error instanceof TimeoutError) 
       { 
        AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext()); 
        builder 
          .setMessage("Error de conexión, sin respuesta del servidor.") 
          .setPositiveButton("Aceptar", new DialogInterface.OnClickListener() 
          { 
           @Override 
           public void onClick(DialogInterface dialog, int id) 
           { 
           } 
          }).show(); 
       } 

       else 

       if (error instanceof NoConnectionError) 
       { 
        AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext()); 
        builder 
          .setMessage("Por favor, conectese a la red.") 
          .setPositiveButton("Aceptar", new DialogInterface.OnClickListener() 
          { 
           @Override 
           public void onClick(DialogInterface dialog, int id) 
           { 
           } 
          }).show(); 
       } 

       else 

       if (error instanceof AuthFailureError) 
       { 
        AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext()); 
        builder 
          .setMessage("Error de autentificación en la red, favor contacte a su proveedor de servicios.") 
          .setPositiveButton("Aceptar", new DialogInterface.OnClickListener() 
          { 
           @Override 
           public void onClick(DialogInterface dialog, int id) 
           { 
           } 
          }).show(); 
       } 

       else 

       if (error instanceof ServerError) 
       { 
        AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext()); 
        builder 
          .setMessage("Error server, sin respuesta del servidor.") 
          .setPositiveButton("Aceptar", new DialogInterface.OnClickListener() 
          { 
           @Override 
           public void onClick(DialogInterface dialog, int id) 
           { 
           } 
          }).show(); 
       } 

       else 

       if (error instanceof NetworkError) 
       { 
        AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext()); 
        builder 
          .setMessage("Error de red, contacte a su proveedor de servicios.") 
          .setPositiveButton("Aceptar", new DialogInterface.OnClickListener() 
          { 
           @Override 
           public void onClick(DialogInterface dialog, int id) 
           { 
           } 
          }).show(); 
       } 

       else 

       if (error instanceof ParseError) 
       { 
        AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext()); 
        builder 
          .setMessage("Error de conversión Parser, contacte a su proveedor de servicios.") 
          .setPositiveButton("Aceptar", new DialogInterface.OnClickListener() 
          { 
           @Override 
           public void onClick(DialogInterface dialog, int id) 
           { 
           } 
          }).show(); 
       } 

      } 

     }) 
{ 
    @Override 
    public Map<String, String> getHeaders() throws AuthFailureError 
    { 
     HashMap<String, String> headers = new HashMap <String, String>(); 
     headers.put("Content-Type", "application/json; charset=utf-8"); 
     headers.put("WWW-Authenticate", "xBasic realm=".concat("")); 
     headers.put("MyToken",sharedPreferences.getString("MyTokenAPI")); 
     return headers; 
    } 
}; 

ControllerSingleton.getInstance().addToReqQueue(jsonObjReq, ""); 
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(20000, 1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 
} 

にしようと、まだそれは二回実行されます。誰かがこの問題を1回だけ実行する必要があるため、この問題をどのように処理するかを知っています。代わりに渡し-1あなたのコードはこれだけのようonce.Somethingと呼ばれるショーをしてみてくださいretryPolicyに1を送信する

+0

完全なコードを表示してください。 –

+0

完全なコードpls –

+0

コードを見なさいManoj – FABiO

答えて

0

: -

jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(20000, -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 

希望、それはあなたの問題を解決します。

関連する問題