2017-06-18 47 views
0
public Boolean getOtp(String mobile, String otp, String accessToken){ 
    Boolean success = false; 

    progress.setVisibility(View.VISIBLE); 
    progress.animate(); 
    Retrofit retrofit = new Retrofit.Builder() 
      .baseUrl(getResources().getString(R.string.baseURL)) 
      .addConverterFactory(GsonConverterFactory.create()) 
      .build(); 
    APIService apiService = retrofit.create(APIService.class); 
    Call<statusResponse> call = apiService.checkOtp(mobile,accessToken , otp); 
    call.enqueue(new Callback<statusResponse>() { 
     @Override 
     public void onResponse(Response<statusResponse> response, Retrofit retrofit) { 
      progress.setVisibility(View.INVISIBLE); 
      statusResponse sp = response.body(); 

      if (sp.getStatus().equals("1")) { 
       success = true; 
       Log.e("Response ", sp.getText() + valueOf(success); 
      } else { 

       Log.e("Response Failed", String.valueOf(sp)); 
       /*Snackbar.make(cl, "Failed to update, please try again", Snackbar.LENGTH_LONG).show();*/ 
      } 
      } 

     @Override 
     public void onFailure(Throwable t) { 

     } 
    }); 
    return success; 
} 

布尔是示出错误将其声明为最终如何为布尔值从改造onResponse方法改变

最终布尔[]成功= {FALSE}; 返回成功[0]

然后它每次都返回false。 响应

{ “地位”: “1”, “文”: “OTP全成”}

+0

第一次检查是你的电话打到服务器或不?使用'response.isSuccessful()实现或不''。 – sushildlh

+0

粘贴你的回应在这里.. – Dev

+0

我得到正确的回应{“状态”:“1”,“文本”:“OTP成功”}获取日志作为“响应OTP成功” –

回答

2

您正在异步调用。只有在通话结束时才会执行onResponse方法。您的return success声明在此之前执行很久,因此返回false