Pass a return value from a method,which is a json array, to android asynctask, doInBackground method as an argument -
the json array passed doinbackground return value of following method.
public jsonarray json_encode(){ string[] log_data; log_data= this.credentials(); jsonobject json_var=new jsonobject(); try{ json_var.put("username" ,log_data[0] ); json_var.put("password" ,log_data[1] ); } catch(jsonexception e){ e.printstacktrace(); } jsonarray json_array=new jsonarray(); json_array.put(json_var); return json_array; }
i need pass return json array doinbackground method argument. how it? both methods in different class , method's return value passed (json array) in first class (main_activity),the second class aysnctask class ( class background_thread extends asynctask ) , need pass return array doinbackground method of second class.
well, if want value in doinbackground() :-
public class youractivity extends activity { ... jsonarray mjsonarray; ... @override protected void oncreate(bundle savedinstancestate) { ... mjsonarray = json_encode(); new yourasynctask().execute(); } private class yourasynctask extends asynctask<void,void,void>{ @override protected void doinbackground(void... params) { //now can use mjsonarray here inner class return null; } } }
Comments
Post a Comment