This code is not working properly ...
The reason is that Your code is in synchronous model
and you are making Asynchronous calls
.
I am assuming that you are doing something after you got some result in onSearchResult
.
So,stop executing your code until you got the response from server, Why because you dont know that the callmay fail sometime.
If you really want to use the value globally ,then
public boolean returnVal=false;
public void checkExist(String name, MyCallback callback) {
getAllRecordFromServer(new SearchCallback() {
@Override
public void onSearchResult(Map<String, Item> itemsMap) {
returnVal=true;
proceedFurther(itemsMap) //your next lines of code in this method.
}
@Override
public void onSearchError(XMLPacket error) {
stopProceedFurther(); //show some error message to user.
}
});