android - AsyncTask in separate object -
i want background tasks in android send request api, can't work way want.
these scripts:
activity class
public class sampleactivity extends activity { private apirequest ar; private string parameters; ... private void callapi() { this.apirequest = new apirequest(this.parameters); } }
apirequest class
public class apirequest { private string response; public apirequest(parameters) { new backgroundtask().execute(parameters); } protected class backgroundtask extends asynctask<string, string, string> { @override protected string doinbackground(string... args) { // stuff here } @override protected void onpostexecute(string response) { this.response = response; } }
somehow, can't seem update response string onpostexecute method. know onpostexecute supposed update ui thread, want update object first, runs in ui thread (i think). how done? can't find really.
@override protected void onpostexecute(string response) { this.response = response; }
in scope, this
refers instance of backgroundtask , not apirequest. i'm surprised code compiles.
change apirequest.this.response = response
.
Comments
Post a Comment