store activity:
public void unlockcup2(){ } main activity:
public void unlock2(){ x = (x-100); imageview img5 = (imageview) findviewbyid(r.id.bluecake); img5.setvisibility(view.visible); } soo, want make when button in store activity(witch calls unlockcup2()) call unlock2 in mainactivity . how do this?
localbroadcastmanager can job. send broadcast in storeactivity , receive in mainactivity , call unlock2()
mainactivity (receiver)
private broadcastreceiver mreceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { // in case, there's 1 type of action, no need check action unlock2(); } }; @override public void oncreate(bundle savedinstancestate) { ... localbroadcastmanager.getinstance(this).registerreceiver(mreceiver, new intentfilter("custom-action-name")); } @override protected void ondestroy() { ... localbroadcastmanager.getinstance(this).unregisterreceiver(mreceiver); } storeactivity (sender)
public void unlockcup2() { ... localbroadcastmanager.getinstance(this) .sendbroadcast(new intent("custom-action-name")); }
Comments
Post a Comment