I am working on an android app with a Widget.
Everything works fine except for one thing.
I debug and code my app on different computers so when I launch the app for the first time i need to reinstall it because of the different debug key. When I try readding my widget after the installation I get the 'problem loading widget' and I need to reboot my phone to get it to work again.
This does not always happen, there are also other strange things that might happen.
- My widget name, in the add widget list screen, gets renamed to 'foo.packagename.WidgetName' instead of the Widget Title.
- The Widget icon gets replaced by the default android launcher icon
- When I try adding the widget and place it on the homescreen, the previewimage gets replaced by a random icon
Beta testers experience the same problems after an update, even with the same key (release version).
Is this an android issue, or is something wrong in my code?
My AppWidgetProvider (partially)
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
final int N = appWidgetIds.length;
SimpleDateFormat fmt = new SimpleDateFormat("EEEE d MMMM");
String date = fmt.format(new Date());
for (int i = 0; i < N; i++) {
RemoteViews remoteViews = updateWidgetListView(context,
appWidgetIds[i], date);
appWidgetManager.updateAppWidget(appWidgetIds[i], remoteViews);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[i], R.id.list);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
@Override
public void onDisabled(Context context) {
Intent intent = new Intent(context, AppService.class);
intent.setAction(AppService.ACTION_UPDATE_WIDGET);
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(sender);
super.onDisabled(context);
}
private RemoteViews updateWidgetListView(Context context, int appWidgetId, String date) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.widget);
Intent svcIntent = new Intent(context, ListWidgetService.class);
remoteViews.setRemoteAdapter(R.id.list, svcIntent);
remoteViews.setEmptyView(R.id.list, R.id.empty_view);
remoteViews.setTextViewText(R.id.widget_sub_title, date);
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
remoteViews.setOnClickPendingIntent(R.id.widget_root, pendingIntent);
return remoteViews;
}
widget_provider.xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="250dp"
android:minHeight="110dp"
android:previewImage="@drawable/ic_launcher"
android:initialLayout="@layout/widget"
android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="0">