Widget doesn't update

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Widget doesn't update

Postby csengyee » Wed Dec 30, 2009 1:50 am

Not sure why my widget doesn't update on the emulator but it updates when I deploy the application to my HTC magic. Anyone can explain why? Below is my code:

public class MyWidget extends AppWidgetProvider {
private RemoteViews views;
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
views = new RemoteViews(context.getPackageName(), R.layout.main);
views.setTextViewText(R.id.item1, Math.random()+"");
appWidgetManager.updateAppWidget(appWidgetId, views);

public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
final int appWidgetId = intent.getExtras().getInt( AppWidgetManager.EXTRA_APPWIDGET_ID,AppWidgetManager.INVALID_APPWIDGET_ID);
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID)
this.onDeleted(context, new int[] { appWidgetId });

}else {
super.onReceive(context, intent);

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
Junior Developer
Junior Developer
Posts: 19
Joined: Mon Jul 13, 2009 3:07 pm


Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests