Here's some more info:
I just learned that an interesting thing happens when I re-run the
code: onUpdate() and onReceive() are called. To state that in more
detail, I go to my code and make a trivial change -- let's say I add a
comment -- and then hit Run and select Android Application and then my
console starts spitting out the typical updates. As soon as it says
"Done!" I get Toast popups on the emulator saying that onUpdate and
onReceive are running. Now here's the interesting part: after they are
called, the widget sitting on my desktop -- the one that wouldn't open
the browser when touched -- *does* open the browser. This kind of
makes sense since onReceive() contains the widget's
setOnClickPendingIntent call, except that onReceive() also runs as
soon as I create the widget (right about the same time that the
configuration activity appears). So it's almost like the code in the
first run of onReceive isn't working but it works the second time. =\
In case it helps, here's my code for onReceive():
public void onReceive(Context context, Intent intent)
{
super.onReceive(context, intent);
String action = intent.getAction();
if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action))
{
Toast.makeText(context, "onReceive()",
Toast.LENGTH_SHORT).show();
RemoteViews views = new RemoteViews(context.getPackageName
(), R.layout.widget);
Intent browsingIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.cnn.com"));
browsingIntent.addCategory(Intent.CATEGORY_BROWSABLE);
browsingIntent.setComponent(new ComponentName
("com.android.browser", "com.android.browser.BrowserActivity"));
PendingIntent pendingIntent = PendingIntent.getActivity
(context, 0, browsingIntent, 0);
views.setOnClickPendingIntent(R.id.Widget, pendingIntent);
AppWidgetManager.getInstance(context).updateAppWidget
(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS),
views);
}
}
On Nov 20, 6:05 pm, Susan <[email protected]> wrote:
> Justin,
>
> Thanks for the suggestion, but as you expected it didn't change the
> outcome. With so many widgets on the market, I'm perplexed that I'm
> unable to make this work. =\ If you do get a chance to compare it to
> your code, I'd be much obliged.
>
> Thanks!
>
> S
>
> On Nov 20, 10:01 am, Justin Anderson <[email protected]> wrote:
>
> > Offhand, the only big difference I see between your code and mine is that
> > you are calling super.onUpdate() and I am not. Try commenting out that line
> > and seeing if that helps...
>
> > I don't think that is the problem, so I will take a look at my code when I
> > get home from work today and see if I notice any other differences.
>
> > Thanks,
> > Justin
>
> > ----------------------------------------------------------------------
> > There are only 10 types of people in the world...
> > Those who know binary and those who don't.
> > ----------------------------------------------------------------------
>
> > On Thu, Nov 19, 2009 at 2:54 PM, Susan <[email protected]> wrote:
> > > I have a widget with a configuration activity. After the configuration
> > > activity runs, I need to call onUpdate(). Unfortunately, when I try to
> > > call onUpdate() nothing actually seems to happen -- the Toast it's
> > > supposed to display never appears. Furthermore, if I don't try to call
> > > onUpdate(), my widget will perform its expected behavior (to open a
> > > browser and go to a particular URL when the user touches the widget).
> > > If I *do* try to call onUpdate(), nothing happens when you touch the
> > > widget. Here are the relevant sections of code:
>
> > > In Widget.java:
>
> > > public void onUpdate(Context context, AppWidgetManager
> > > appWidgetManager, int[] appWidgetIds)
> > > {
> > > super.onUpdate(context, appWidgetManager, appWidgetIds);
> > > // just to verify that it's running
> > > Toast.makeText(context, "onUpdate()", Toast.LENGTH_SHORT).show();
> > > // ^^^ This Toast never pops up! Why not? ^^^
> > > }
>
> > > In WidgetConfiguration.java I have tried two different methods that
> > > both give the same results (described above), oddly.
>
> > > Method 1:
>
> > > public void onClick(View v) {
>
> > > Context context = getBaseContext();
> > > Intent intent = new Intent();
> > > intent = getIntent();
> > > setResult(RESULT_OK, intent);
> > > Toast.makeText(getBaseContext(), url.getText(),
> > > Toast.LENGTH_SHORT).show();
> > > ComponentName me = new ComponentName( context,
> > > nEx.Software.Tutorials.Widgets.AnalogClock.Widget.class );
> > > RemoteViews view = new
> > > RemoteViews(context.getPackageName(),
> > > R.layout.widget);
>
> > > AppWidgetManager.getInstance(context).updateAppWidget(me,
> > > view);
> > > finish();
> > > }
> > > //Note: I'm not affiliated with the nEx.Software people. I just
> > > used one of their tutorials as the base for my code.
>
> > > Method 2:
>
> > > public void onClick(View v) {
>
> > > Context context = getBaseContext();
> > > Intent intent = new Intent();
> > > intent = getIntent();
> > > Bundle extras = intent.getExtras();
> > > int appWidgetId = extras.getInt
> > > (AppWidgetManager.EXTRA_APPWIDGET_ID);
> > > if (extras != null) {
> > > appWidgetId = extras.getInt(
> > > AppWidgetManager.EXTRA_APPWIDGET_ID,
> > > AppWidgetManager.INVALID_APPWIDGET_ID);
> > > }
>
> > > AppWidgetManager appWidgetManager =
> > > AppWidgetManager.getInstance(context);
> > > RemoteViews views = new
> > > RemoteViews(context.getPackageName
> > > (), R.layout.widget);
> > > appWidgetManager.updateAppWidget(appWidgetId,
> > > views);
>
> > > intent.putExtra
> > > ("nEx.Software.Tutorials.Widgets.AnalogClock.URL", url.getText());
> > > setResult(RESULT_OK, intent);
> > > Toast.makeText(getBaseContext(), url.getText(),
> > > Toast.LENGTH_SHORT).show();
>
> > > finish();
> > > }
>
> > > What am I missing? I've tried to follow the Dev Guide's example very
> > > closely (as well as some code I found in another onUpdate()-related
> > > post), but it's just not working for me. =(
>
> > > Thanks!
>
> > > S
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Beginners" group.
> > > To post to this group, send email to [email protected]
> > > To unsubscribe from this group, send email to
> > > [email protected]<android-beginners%[email protected]>
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-beginners?hl=en
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en