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]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en