FileDocCategorySizeDatePackage
ExampleBroadcastReceiver.javaAPI DocAndroid 1.5 API2424Wed May 06 22:41:08 BST 2009com.example.android.apis.appwidget

ExampleBroadcastReceiver

public class ExampleBroadcastReceiver extends android.content.BroadcastReceiver
A BroadcastReceiver that listens for updates for the ExampleAppWidgetProvider. This BroadcastReceiver starts off disabled, and we only enable it when there is a widget instance created, in order to only receive notifications when we need them.

Fields Summary
Constructors Summary
Methods Summary
public voidonReceive(android.content.Context context, android.content.Intent intent)

        Log.d("ExmampleBroadcastReceiver", "intent=" + intent);

        // For our example, we'll also update all of the widgets when the timezone
        // changes, or the user or network sets the time.
        String action = intent.getAction();
        if (action.equals(Intent.ACTION_TIMEZONE_CHANGED)
                || action.equals(Intent.ACTION_TIME_CHANGED)) {
            AppWidgetManager gm = AppWidgetManager.getInstance(context);
            ArrayList<Integer> appWidgetIds = new ArrayList();
            ArrayList<String> texts = new ArrayList();

            ExampleAppWidgetConfigure.loadAllTitlePrefs(context, appWidgetIds, texts);

            final int N = appWidgetIds.size();
            for (int i=0; i<N; i++) {
                ExampleAppWidgetProvider.updateAppWidget(context, gm, appWidgetIds.get(i), texts.get(i));
            }
        }