java - Using AsyncTask to login user -


i need user , save variable.

public class mainactivity extends actionbaractivity  {     user user = new logintask2().execute(""); }  class logintask2 extends asynctask<string, void, user> {     private exception exception;     public string hash = "";      protected string doinbackground(string... t) {         restclient restclient = new httprestclient();         restclient.setuseragent("bot/1.0 name");          // connect user         user user = new user(restclient, "user", "somepass");         try {             user.connect();             //hash = user.getmodhash();             return user;         } catch (exception e) {             e.printstacktrace();             this.exception = e;             return null;         }     }      protected void onpostexecute(string string) {      } } 

it looks work, don't know how user. code error:

error:(49, 47) error: incompatible types required: string found:    asynctask<string,void,string> 

could give me advice how change code?

your async task declared:

class logintask2 extends asynctask<string, void, user> {     protected string doinbackground(string... t) { 

in order avoid incompatible types error, need make doinbackground return user object.

    protected user doinbackground(string... t) { 

see: http://developer.android.com/reference/android/os/asynctask.html

the code have above:

user user = new logintask2().execute(""); 

will fail because must execute async task , later use return value. access returned user object setting field in mainactivity , using object later once asynctask completes.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -