java - Can't return value from method containing class which extends AsyncTask -


i trying return boolean method checkinvited(). method contains class extends asynctask<void,void,string>. full method

public boolean checkinvited(string player_id){      final string g_id = game_id;     final string fr_id = player_id;      class checkinvited extends asynctask<void, void, string>{         boolean invited;         progressdialog loading;         @override         protected void onpreexecute(){             super.onpreexecute();             loading = progressdialog.show(invitefriends.this,"checking invite status","please wait...",false,false);         }          @override         protected void onpostexecute(string s){             super.onpostexecute(s);             loading.dismiss();             json_string = s;             if (s.trim().equals("0")){                 invited = false;             } else {                 invited = true;             }          }          @override         protected string doinbackground(void... params){              hashmap<string, string> hashmap = new hashmap<>();             hashmap.put(config.key_invites_game_id, g_id);             hashmap.put(config.key_invites_player_id, fr_id);              requesthandler rh = new requesthandler();             string s = rh.sendpostrequest(config.url_check_invited, hashmap);             return s;         }     }     checkinvited ci = new checkinvited();     ci.execute();     return ci.invited; } 

this method calls predefined method of sendpostrequest() contacts mysql database through php. problem getting checkinvited() method return true or false. return false when know @ least 1 of results should true.

thanks in advance help.

it returns false because async task runs in seperate thread , might take long execute depending on carious factors. returning value before async task completes.

i suggest calling method requires true or false onpostexecute, onpostexecute runs after doinbackground completes.


Comments