Using bundle in Async Task,android -
how values bundle in asynctask doinbackground() method, consist of url , string?
in activity:
bundle bundle = new bundle(); bundle.putstring("url", url); bundle.putstring("json",asyn.tostring()); inte.putextras(bundle); jsonobject responsefromserver = asyn.execute(bundle); and in asynctask not still able extract values.
there no need use bundle here, can pass in strings varargs doinbackground() takes.
you call this, json jsonobject:
asyn.execute(url, json.tostring()); then, make doinbackground() take string varargs:
class asyn extends asynctask<string, void, void> { @override protected void doinbackground(string... arg0) { string url = arg0[0]; string json = arg0[1]; jsonobject obj = new jsonobject(json); } } if want use bundle, call now:
bundle bundle = new bundle(); bundle.putstring("url", url); bundle.putstring("json",json.tostring()); //inte.putextras(bundle); //not needed asyn.execute(bundle); then make doinbackground() take bundle varargs:
class asyn extends asynctask<bundle, void, void> { @override protected void doinbackground(bundle... arg0) { bundle b = arg0[0]; string url = b.getstring("url"); string json = b.getstring("json"); jsonobject obj = new jsonobject(json); } } in addition, should not trying capture return value asynctask. if asynctask subclass of activity, set value in onpostexecute(), , call method in enclosing activity.
for other ways it, see post.
Comments
Post a Comment