At the end of the onReceive function onReceive you can simply create a RemoteView and update the widget:
ComponentName name = new ComponentName(context, WordWidget.class); int[] ids = appWidgetManager.getAppWidgetIds(name); if(ids != null && ids.length > 0){ RemoteView remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget ); remoteViews.setTextViewText( R.id.widget_title, context.getString(R.id.new_widget_title)); remoteViews.setTextViewText( R.id.widget_textview, context.getString(R.id.new_widget_text)); Intent configIntent = new Intent(context, SuitAuto.class); configIntent.setAction(ACTION_WIDGET_CONFIGURE); Intent active = new Intent(context, WordWidget.class); active.setAction(ACTION_WIDGET_RECEIVER); active.putExtra("msg", "Message for Button 1"); PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0); remoteViews.setOnClickPendingIntent(R.id.update, actionPendingIntent); remoteViews.setOnClickPendingIntent(R.id.Lilo, configPendingIntent); appWidgetManager.updateAppWidget(ids, remoteViews ); }
I believe that you will also need to set intentions: if you do not, the buttons will stop working after updating RemoteView.
source share