How to access a TextView element in a BroadcastReceiver

Posted by ric03uec on Stack Overflow See other posts from Stack Overflow or by ric03uec
Published on 2011-01-16T17:40:26Z Indexed on 2011/01/17 3:53 UTC
Read the original article Hit count: 279

Hello,
I am testing a simple widget in android and using Alarms to update a TextView at regular intervals. The problem is that in the BroadcastReceiver class I cannot access the TextView element, which I want to get updated when the alarm expires. The class is being called properly because the Toast i have put there is giving the appropriate message. The following code is from the class where I configure the widget and set the timers.

 public void onCreate(Bundle bundle) {
     super.onCreate(bundle);

     Intent intent = getIntent();
     Bundle extras = intent.getExtras();
     if(extras != null){
      mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
      AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(WidgetConfigure.this);
      RemoteViews views = new RemoteViews(WidgetConfigure.this.getPackageName(), R.layout.widget_layout);
      views.setTextViewText(R.id.quote, "Widget Loaded From Activity");
      appWidgetManager.updateAppWidget(mWidgetId, views);

      setTimer(); //set the timers...
      setResult();// set the result...
     }
 }

Now i want to update the same TextView when the BroadCastReceiver is called after the timer expires. I have tried the code provided in the ExampleAppWidget example provided in android api demos and that isnt working out. How can i set the required text?
Thankx in advance

© Stack Overflow or respective owner

Related posts about android

Related posts about android-widget