Available for

download on RemoteViews views = new RemoteViews(context.getPackageName(), Wrox.com R.layout.my_remote_layout);

To use Remote Views on widgets, call the static getinstance method to return an instance of the App Widget Manager and use it to find identifiers for each instance of a particular widget class, as in this continuation of Listing 10-5:

// Get the App Widget Manager.

AppWidgetManager appWidgetManager = AppWidgetManager.getlnstance(context); // Retrieve the identifiers for each instance of your chosen widget. ComponentName thisWidget = new ComponentName(context, MyAppWidget.class); int[] appWidgetlds = appWidgetManager.getAppWidgetlds(thisWidget);

When you've finished making changes to a Remote Views object, apply those modifications to one or more widgets by calling the updateAppWidget method on the App Widget Manager, passing in either an individual widget ID or an array of identifiers:

appWidgetManager.updateAppWidget(appWidgetIds, views);

The standard pattern used to update widget UI is to iterate over the widget ID array as shown in Listing 10-6. This enables you to apply different UI values to each widget based on its configuration settings or UI requirements.

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