I use the following function to check the username and password from the web service. I want to use this function in different activities. But before I get a response from the server, the function reaches the end and returns false. Please suggest me a way to solve this issue with sample code.
Thank you.
public boolean checkUserPass(String username, String password) {
userExist = false;
UserModel user = new UserModel();
user.setUsername(username);
user.setPassword(password);
Assistant.assistant.client.userCheck(user).enqueue(new Callback<Boolean>() {
@Override
public void onResponse(@NonNull Call<Boolean> call, @NonNull Response<Boolean> response) {
if (response.isSuccessful()) {
userExist = response.body();
Log.i("MyTag", response.body().toString());
} else {
Log.i("MyTag", "Not Success " + response);
}
}
@Override
public void onFailure(Call call, Throwable throwable) {
Log.e("MyTag", "Fail");
}
});
return userExist;
}
I searched all the posts but didn’t get a proper answer.