android - How to return a value from Asynctask to activity -


how return value asynctask (different class) activity called asynctask , here have followed intsruction given in following link how result of onpostexecute() main activity because asynctask separate class? @helmib's

i have done , returning result activity's method processfinish() , problem lost activity control or focus, not further actions using asynctask's result, because activity's members becomes null.

how proceed ?

protected void onpostexecute(void result) {     super.onpostexecute(result);      if (pdialog != null)     {         pdialog.cancel();     }      if (stringutil.hasvalue(responsexmlstring))     {         if (integer.parseint(apputil.getxpathvalue("result/errorno",apputil.builddocument(responsexmlstring))) == 0)          {             asyncresponse.processfinish(responsexmlstring);          }     }   @override public void processfinish(object output)  {     log.d("response asynchronous task:", (string) output);      displayview(position,(string) output); }  private void displayview(int position,string responsexml) {     // update main content replacing fragments     boolean isfragment = true;     fragment fragment = null;     /*//for handling press      if (getintent().getbooleanextra("frompassbook", false) )     {         getintent().putextra("frompassbook", false);         position = 7;     }     if (getintent().getbooleanextra("tocustomeracocunts", false) )     {         getintent().putextra("tocustomeracocunts", false);         position = 1;     }*/      switch (position)     {         case 0:             fragment = new chartfragment();             settitle(getresources().getstring(r.string.wealth));             break;          default:             break;     }      if (fragment != null && isfragment)     {         fragmentmanager fragmentmanager = getsupportfragmentmanager();         fragmenttransaction ft =fragmentmanager.begintransaction();         fragmentstack.push(fragment);          //passing data fragment         if (stringutil.hasvalue(responsexml))          {             bundle bundle = new bundle();             bundle.putstring("responsexml", responsexml);             fragment.setarguments(bundle);         }          ft.replace(r.id.frame_container, fragment).commit();          // update selected item , title, close drawer         listview.setitemchecked(position, true);         listview.setselection(position);         mdrawerlayout.closedrawer(listview);     }     else     {         // error in creating fragment         log.e("mainactivity", "error in creating fragment");     } } private void callservice(int position) {     string input = "";     asynccallws asynccallws;     switch (position)     {         case 0:             input = "<parm><processid>101</processid><mobileno>" + mobilenumber + "</mobileno></parm>";             asynccallws = new asynccallws(mainactivity.this, input, position,new mainactivity());             asynccallws.execute();             break; }  asynctask class constructor  

`asyncresponse asyncresponse;

public asynccallws(context context,string input,int position,asyncresponse response ) {     this.context = context;     this.inputtoservice = input;     this.position = position;     asyncresponse = response; }` 

well, problem in line of code:

asynccallws = new asynccallws(mainactivity.this, input, position,new mainactivity()); 

or, particularly, in statement new mainactivity(). create new instance of mainactivity class here , use callback. obviously, have fields non-initialized. use mainactivity.this instead of new mainactivity(). , please remember android manages of activities. never want create 1 yourself.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -