android - Call widget's onUpdate method from the app's main activity -
i'm working on android application includes widget. main interface of app simple activity, of things users can in activity make necessary update widget - i.e. run onupdate method.
how can trigger method activity? looking @ other questions, i've been able write code changes layout, doesn't seem run onupdate (since i'm left empty layout , none of data added during onupdate).
any ideas or code samples appreciated!
i still pretty new android, accomplished 3 steps:
first, put contents of appwidgetprovider.onupdate in method (myupdate(context)
).
second, overrode appwidgetprovider.onreceive() this:
public void onreceive(final context context, final intent intent) { super.onreceive(context, intent); if (my_public_static_string.equals(intent.getaction())) { myupdate(context); } }
third, other activity, send generic broadcast action set on intent.
intent updatewidgetintent = new intent(context, mywidget.class); updatewidgetintent.setaction(mywidget.my_public_static_string); context.sendbroadcast(updatewidgetintent);
this have down side of having find appwidgetmanager context , app widget ids, instead of nice interface onupdate gives you. skeptical right approach. best of luck.
myupdate(context) starts this:
appwidgetmanager appwidgetmanager = appwidgetmanager.getinstance(context); int[] appwidgetids = appwidgetmanager.getappwidgetids(new componentname(context, this.getclass()));
Comments
Post a Comment