Search code examples
androidandroid-widgetbroadcastreceiverclickable

First added widget not clickable. 2nd is


in my Broadcastreceiver, which is a widget at the same time. At the time I add the widget for the first time after installation, it is not clickable. The 2nd widget I add is clickable. While the first widget is still not clickable.

This errors happened while testing different versions in the emulator. I have no other device at hand, which I can reset all the time. For testing I always start with "Wipe user data" to be sure it is a fresh installation.

It does work for 1.6, but not for 2.x

My preference screen is a manual independent activity, which has to be started separably.

If you need more information, please tell me.

Here my code for making it clickable:

    @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);
    Log.d(LOG_TAG, "Update");
    for (int id : appWidgetIds) {
        Intent intent = new Intent(ACTION);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
        //make widget clickable
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
        remoteViews.setOnClickPendingIntent(R.id.imageview, pendingIntent);
        appWidgetManager.updateAppWidget(id, remoteViews);
    }
}

Solution

  • I found the error.

    It is a bug in the android emulator alias AVD . Damn thing. Hope this helps others not wasting so much time in an non existing error.

    http://code.google.com/p/android/issues/detail?id=8889

    bug id 8889 "appWidgetManager.updateAppWidget not updating widgets on fresh AVDs under 2.0, 2.1"

    A workaround is after starting with Wipe user data(I disabled save to snapshot for this - tested not with enabled). Than exit. Than start again without wipe. Other wrote you can use ctrl+F11 two times to change to landscape mode and back.