android - UI components not getting updated in onReceiveResult after finishing service -


hi using service load data url in tutorial( background service tutorial ) .

i have 2 activities. 1st 1 going activity start service , 2nd 1 start service. when start service 2nd activity , waits there until service finishes, ui components gets updated properly.

but when start service 2nd activity, finishes , start 2nd activity again ui components not getting updated when service finishes. fetched data correctly coming onreceiveresult ui views not getting updated.

why happening? how can fix this?

my code:

    @override     protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      /* allow activity show indeterminate progressbar */     requestwindowfeature(window.feature_indeterminate_progress);     setcontentview(r.layout.activity_my);      btnstartserv=(button)findviewbyid(r.id.buttonserv);        /* initialize listview */     //listview = (listview) findviewbyid(r.id.listview);      /* starting download service */     mreceiver = new downloadresultreceiver(new handler());     mreceiver.setreceiver(myactivity.this);      btnstartserv.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {              toast.maketext(myactivity.this,"service started",toast.length_short).show();             intent intent = new intent(intent.action_sync, null, myactivity.this, downloadservice.class);               /* send optional extras download intentservice */             intent.putextra("url", url);             intent.putextra("receiver", mreceiver);             intent.putextra("requestid", 101);              startservice(intent);            }     }); } 

onreceiveresult:

 @override  public void onreceiveresult(int resultcode, bundle resultdata) {     switch (resultcode) {         case downloadservice.status_running:              setprogressbarindeterminatevisibility(true);             break;         case downloadservice.status_finished:              setcontentview(r.layout.activity_my);              toast.maketext(myactivity.this,"service finished",toast.length_short).show();              /* hide progress & extract result bundle */             setprogressbarindeterminatevisibility(false);              string[] results = resultdata.getstringarray("result");              system.out.println("size"+results.length);              listview = (listview) findviewbyid(r.id.listview);              if(listview == null ){                 system.out.println("listview null");              }else{                 system.out.println("listview not null");              }              btnstartserv=(button)findviewbyid(r.id.buttonserv);             btnstartserv.settext("service finished!!!");              /* update listview result */             arrayadapter = new arrayadapter(myactivity.this,       android.r.layout.simple_list_item_1, results);             listview.setadapter(arrayadapter);              break;         case downloadservice.status_error:             /* handle error */             string error = resultdata.getstring(intent.extra_text);             toast.maketext(this, error, toast.length_long).show();             break;     } }  

edit: added downloadresultreceiver class

downloadresultreceiver:

public class downloadresultreceiver extends resultreceiver { private receiver mreceiver;  public downloadresultreceiver(handler handler) {     super(handler); }  public void setreceiver(receiver receiver) {     mreceiver = receiver; }  public interface receiver {     public void onreceiveresult(int resultcode, bundle resultdata); }  @override protected void onreceiveresult(int resultcode, bundle resultdata) {     if (mreceiver != null) {         mreceiver.onreceiveresult(resultcode, resultdata);     } } 

}


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -