Reputation: 131
test=0;
Phone phone=new Phone();
phone.phone="01093575777";
WebService.getInstance().getApi().checkNumber(phone).enqueue(new Callback<MainResponse>() {
@Override
public void onResponse(Call<MainResponse> call, Response<MainResponse> response) {
if (response.body().status==1){
test++;
//----------------->first place
}
}
@Override
public void onFailure(Call<MainResponse> call, Throwable t) {
}
});
//----------------->second place
when I print the value from first place it is equal to 1 and that is what i want
but when printing it from second place it's equal to 0
why ?? and how to solve this
Upvotes: 0
Views: 42
Reputation: 43728
I assume you mean the value of test
. You schedule a call to check the number asynchronously. Some time in the future the result will come back and onResponse
will be executed. This happens after you reach "second place". Therefore test
is still 0 when you print it there.
Upvotes: 1