Мне нужно показать загрузочную анимацию в моем проекте Android для ожидания ответа. я пытаюсь показать загрузочное сообщение. Мне нужно спрятаться после получения ответа.
private void searchCustomer(final String username, final String
password, final String baseUrl, final ProgressDialog dialog) {
AsyncTask<String, String, String> checkLogin = new AsyncTask<String, String, String>() {
final ProgressDialog dialog = new ProgressDialog(MainActivity.this);
@Override
protected String doInBackground(String... strings) {
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n\t\"custUserName\": \""+ username +"\",\n\t\"custPassword\": \""+ password +"\"\n}");
Request request = new Request.Builder()
.url(baseUrl + "customerLogin")
.post(body)
.addHeader("Content-Type", "application/json")
.build();
try {
Response response = okHttpClient.newCall(request).execute();
return response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
@Override
protected void onPostExecute(String s) {
dialog.setMessage("Processing...");
dialog.show();
StringBuilder sb = new StringBuilder();
char[] temp = s.toCharArray();
for (char current : temp) {
if (current != '"') {
sb.append(current);
}
}
String s1 = sb.toString();
if (s1.equals("true")) {
Notification.showSuccessMdToast("Login Successful", getApplicationContext());
Intent customerNav = new Intent(MainActivity.this, CustomerNav.class);
startActivity(customerNav);
}
}
};
checkLogin.execute();
}
в посте Выполнить ответ получен как true. но диалог обработки не скрывается.