java - How can I return multiple strings from a JSON query within an asynctask? -


i'm working on group project , trying string values json query within asynctask, in order send them via intents second activity. trouble having when string taken out of asynctask, becomes null. how can solved?

public class connecttask extends asynctask<string,string,tcpclient> {      string filmid, name, certificate, duration, director, description, releasedate, cast;      @override     protected tcpclient doinbackground(string... message) {          //we create tcpclient object ,         mtcpclient = new tcpclient(new tcpclient.onmessagereceived() {             @override             //here messagereceived method implemented             public void messagereceived(string message) {                 //this method calls onprogressupdate                   log.e("tcp client", message);                     try                  {                     jsonobject json = new jsonobject(message);                     filmid = (string) json.get("filmid");                     name = (string) json.get("name");                     certificate = (string) json.get("certificate");                     duration =(string) json.get("duration");                     director = (string) json.get("director");                     description = (string) json.get("description");                     releasedate = (string) json.get("releasedate");                     cast = (string) json.get("cast");                     log.e("filmid: ", filmid);                     log.e("name: ", name);                     log.e("cert: ", certificate);                     log.e("duration: ", duration);                     log.e("director: ", director);                     log.e("description: ", description);                     log.e("releasedate: ", releasedate);                     log.e("cast: ", cast);                    }                  catch (jsonexception e)                 {                     // todo auto-generated catch block                     e.printstacktrace();                 }                }         });           mtcpclient.run("gtf 02");         system.out.println(json[1]);                return null;        }     protected void onpostexecute()     {     json[0] = filmid;     json[1] = name;        } }   public void mloadfilminfo(view view)  {      //filmid = "gtf "+ buttonname;     new connecttask().execute();      intent filminfo = new intent(this, filminfo.class);     filminfo.putextra("namepass", json[1]);        startactivity(filminfo);   } 

this code asynctask , passing second activity.

any appreciated.

try this, async thread async , can't determ when over:

public class connecttask extends asynctask<string,string,string[]> {      string filmid, name, certificate, duration, director, description, releasedate, cast;      @override     protected string[] doinbackground(string... message) {     string[] jsonarr = new string[9];         //we create tcpclient object ,         mtcpclient = new tcpclient(new tcpclient.onmessagereceived() {             @override             //here messagereceived method implemented             public void messagereceived(string message) {                 //this method calls onprogressupdate                   log.e("tcp client", message);                     try                  {                     jsonobject json = new jsonobject(message);                     filmid = (string) json.get("filmid");                     name = (string) json.get("name");                     certificate = (string) json.get("certificate");                     duration =(string) json.get("duration");                     director = (string) json.get("director");                     description = (string) json.get("description");                     releasedate = (string) json.get("releasedate");                     cast = (string) json.get("cast");                     log.e("filmid: ", filmid);                     log.e("name: ", name);                     log.e("cert: ", certificate);                     log.e("duration: ", duration);                     log.e("director: ", director);                     log.e("description: ", description);                     log.e("releasedate: ", releasedate);                     log.e("cast: ", cast);      jsonarr [0] = filmid; jsonarr [1] = name;                  }                  catch (jsonexception e)                 {                     // todo auto-generated catch block                     e.printstacktrace();                 }                }         });           mtcpclient.run("gtf 02");         system.out.println(jsonarr [1]);                return jsonarr ;        }     protected void onpostexecute(string[] json)     {      intent filminfo = new intent(this, filminfo.class);     filminfo.putextra("namepass", json[1]);        startactivity(filminfo);      } }   public void mloadfilminfo(view view)  {      //filmid = "gtf "+ buttonname;     new connecttask().execute();    } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -