The background image of the widget created in the application suddenly stopped appearing. In addition, the widget no longer responds to click events when the application starts in the emulator. Here are the Android project files:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.widgetexample" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="-4" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".ConfigureActivity"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /> </intent-filter> </activity> <receiver android:name="WidgetProvider"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widgetprovider" /> </receiver> </application> </manifest>
Res /XML/widgetprovider.xml
<?xml version="1.0" encoding="utf-8"?> <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="72dp" android:minHeight="72dp" android:updatePeriodMillis="0" android:initialLayout="@layout/widget" android:configure="com.widgetexample.ConfigureActivity"> </appwidget-provider>
Res / layout / widget.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/widget_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:background="@drawable/widget_background" /> </LinearLayout>
SRC / COM / widgetexample / WidgetProvider.java
package com.widgetexample; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.content.Intent; import android.widget.RemoteViews; public class WidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int widgetIndex = 0; widgetIndex < appWidgetIds.length; widgetIndex++) { int appWidgetId = appWidgetIds[widgetIndex]; Intent intent = new Intent(context, ConfigureActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); RemoteViews mRemoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); mRemoteViews.setOnClickPendingIntent(R.id.widget_button, pendingIntent); appWidgetManager.updateAppWidget(appWidgetId, mRemoteViews); } } }
src/com/widgetexample/ConfigureActivity.java and res/drawable/widget_background.png both exist. I can open the latter in a standard image viewer. When executed, the widget appears in this screenshot: http://i.stack.imgur.com/b43Ya.png . The logcat output is quite long to include here, but this is one line that I noticed that seems relevant.
08-22 19:04:46.182: WARN/AppWidgetHostView(100): can't inflate defaultView because mInfo is missing
This error appears in the Android source for android.appwidget.AppWidgetHostView , but I'm not sure how to fix the problem, and Google provides some useful error information.
Has anyone else experienced this or found a fix? I can replicate this problem with a completely new project, and all the links to the source files and resources seem consistent, so I wonder if the problem is in my development environment. All reviews are welcome.