java - Android BroadcastReceiver onReceive Update TextView in MainActivity -


in mainactivity have textview: textv1. have method in mainactivity updates textview:

public void updatethetextview(final string t) {     mainactivity.this.runonuithread(new runnable() {         public void run() {             textview textv1 = (textview) findviewbyid(r.id.textv1);             textv1.settext(t);         }     }); } 

in broadcasrreceiver need update text in textv1 in mainactivity.

public class notifalarm extends broadcastreceiver {     @override     public void onreceive(context context, intent intent) {             // other things done here notification              // need update textv1 in mainactivity here     } } 

how can done? broadcastreceiver run service. code cannot change. can access , change textv1 in mainactivity onreceive()? i've tried many things fail.

in mainactivity initialize variable of mainactivity class below.

public class mainactivity extends activity {     private static mainactivity ins;     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         ins = this;          }      public static mainactivity  getinstace(){         return ins;     }      public void updatethetextview(final string t) {         mainactivity.this.runonuithread(new runnable() {             public void run() {                 textview textv1 = (textview) findviewbyid(r.id.textv1);                 textv1.settext(t);             }         });     } }   public class notifalarm extends broadcastreceiver {     @override     public void onreceive(context context, intent intent) {         try {             mainactivity  .getinstace().updatethetextview("string");         } catch (exception e) {          }                } } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -