tags:

views:

163

answers:

1

I wrote a home screen widget with one image on it. When the image is clicked, browser will be opened for a url link. Generally, it is working. But a weird thing is that, when I click background, then click the picture, the browser will not be open. Until I click the second time on the picture, the browser opens. The steps to reproduce is below:

  1. Click on the home screen widget background.
  2. Click on the image on the home screen. The browser is not opened.
  3. Click on the image again. The browser is opened.

If I didn't click on the background, the image will react to click very well, i.e. browser will be open when the image is clicked the first time.

The widget XML file is as below:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget"
android:layout_width="320dip" android:layout_height="200dip"
    android:background="@drawable/prt_base"
>
    <ImageView android:id="@+id/picture1"
        android:layout_width="134dip"
        android:layout_height="102dip"
        android:layout_marginLeft="62dip"
        android:layout_marginTop="6dip"
        android:scaleType="center"
                android:src="@drawable/picture1"
    />
</RelativeLayout>

The code to set OnClick on the picture1 ImageView is as below:

                        defineIntent = new Intent(Intent.ACTION_VIEW, Uri
                                .parse("http://www.google.com"));
                        pendingIntent = PendingIntent
                                .getActivity(context,
                                        0 /* no requestCode */,
                                        defineIntent, 0 /* no flags */);
                        updateViews.setOnClickPendingIntent(
                                picId, pendingIntent);

Anyone knows what's wrong?

Thanks.

+1  A: 

RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.mywidget);

    Intent defineIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
        PendingIntent pendingIntent = PendingIntent.getActivity(context,
                0 , defineIntent, 0 );
   updateViews.setOnClickPendingIntent(picId, pendingIntent);

   appWidgetManager.updateAppWidget(appWidgetId, updateViews );

it will work!

could you post your appwidget-provider ???

Jorgesys
My Code is exactly like yours.It worked most of the time, except that, if I clicked the background area of the widget but not the image, then I had to click on the image twice to make the browser open.
I changed the code in http://android-developers.blogspot.com/2009/04/introducing-home-screen-widgets-and.html by replacing one statement line from updateViews.setOnClickPendingIntent(R.id.widget, pendingIntent); to updateViews.setOnClickPendingIntent(R.id.definition, pendingIntent);The modified code has the exact weird behavior as my code. Maybe it is a bug in Android?
yep, i was experiencing the same issue, I was testing with cupcake :o
Jorgesys