Android Fragment + AsyncTask -


in fragment i'm using 'asynctask' retrieve data url. main purpose of code access data (via asynctask) , pass 'jsonarray' fragment. problem is, on fragment side, when check variable should have result error saying variable null.

here code:

    public class myfragment extends listfragment {         //this variable should have result asynctask         jsonarray myresult = null;          @override         public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {             (...)             //execute asynctask             new getresult().execute(email, password);             (...)         }          //the asynctask         private class getresult extends asynctask<string, void, jsonarray> {             @override             protected jsonarray doinbackground(string... params) {                  (...)                  jsonarray jsonarray = (jsonarray) json.get("customer");                 return jsonarray;             }              protected void onpostexecute(jsonarray result){                 (...)                 //this try pass data fragment                 myfragment.this.myresult = result;             }          }       } 

can can me that? thank in advance.

are using value after postexecute method. should know after calling execute, code on main thread still runs , after postexecute has completed, have value.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -