Updating Android Home Screen TextView
Posted
by jmontex2
on Stack Overflow
See other posts from Stack Overflow
or by jmontex2
Published on 2010-06-11T13:10:58Z
Indexed on
2010/06/11
13:12 UTC
Read the original article
Hit count: 305
Hi,
How can we update the View of a Home Screen Widget on the onReceive method of AppWidgetProvider?.
I am trying to update the TextView of my Home screen widget but it seems that I cant access the TextView of my AppWidgetProvider on onReceive method.
Here is a sample code of my onReceive
public void onReceive(Context context,Intent intent) {
final String action = intent.getAction();
if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
final int appWidgetId = intent.getExtras().getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
this.onDeleted(context, new int[] { appWidgetId });
}
} else {
if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
String msg = "null";
try {
msg = intent.getStringExtra("msg");
} catch (NullPointerException e) {
}
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
// code for gathering the text to update the TextView
}
}
super.onReceive(context, intent);
}
© Stack Overflow or respective owner