I am trying to get a response in 30 seconds but I am not able to get it in time. I am using Retrofit 2
to make an API call. In Postman
checking with emailId
and password
getting success response. My application also getting success response but after success, activity is not moving to next activity.
Can anyone help me with Retrofit
to set a timeout.
String url = "xxxxxx";
Retrofit retrofit = null;
Log.d("123", "retrofit");
if (retrofit == null) {
retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).build();
Log.d("123", "build();");
}
final ProgressDialog dialog = new ProgressDialog(LoginActivity.this);
dialog.setMessage("Authenticating...." + 30000 / 1000 + " Second(s)");
dialog.setIndeterminate(false);
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
// You don't need anything here
dialog.setMessage("Authenticating....");
if (!dialog.isShowing()) dialog.show();
}
public void onFinish() {
if (dialog.isShowing()) dialog.dismiss();
}
}.start();
API1 service = retrofit.create(API1.class);
Call<Login> call = service.authenticate(emailId, password);
Log.i(TAG, "Sending---" + url + service + url + "\n" + "emailId:" + emailId + "\n" + "password:" + password);
call.enqueue(new Callback<Login>() {
@Override
public void onResponse(Call<Login> call, Response<Login> response) {
if (response != null && response.isSuccessful() && response.code() == 200) {
String status = response.body().getStatus().toString();
Log.i(status, "success");
if (status.equals("success")) {
// dialog.dismiss();
Toast.makeText(LoginActivity.this, "Login successfully", Toast.LENGTH_SHORT).show();
Intent mainIntent;
mainIntent = new Intent(LoginActivity.this, DeviceControlActivity.class);
startActivity(mainIntent);
finish();
} else {
Toast.makeText(LoginActivity.this, "No Response from the server", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(LoginActivity.this, "Invalid EmailId and password", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<Login> call, Throwable t) {
// Toast.makeText(LoginActivity.this, "Some error occurred -> ", Toast.LENGTH_LONG).show();;
// dialog.dismiss();
}
});