Listing 1014 Updating App Widgets based on broadcast Intents

public static String FORCE_WIDGET_UPDATE = "com.paad.chapter9.FORCE_WIDGET_UPDATE";

@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent);

if (FORCE_WIDGET_UPDATE.equals(intent.getAction())) { // TODO Update widget UI.

To trigger an update of your widget at any point in your application, you can broadcast an Intent using this action:

context.sendBroadcast(new Intent(FORCE_WIDGET_UPDATE));

This technique is particularly useful for reacting to system, user, or application events — like a data refresh, or a user action such as clicking buttons on the widget itself. You can also register for system event broadcasts such as changes to network connectivity, battery level, or screen brightness.

Was this article helpful?

0 0
Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide

Post a comment