The application has a regular widget with three TextView . From SharedPreferences data is loaded, which is processed in the methods and the result of the processing is recorded in TextView . After the phone is rebooted, all data is dropped into units and the widget ceases to be clickable. The problem is solved after updating the widget after the time specified in the settings. This problem was also noticed on a weak phone, when transferring a widget from one screen to another. Tell me how to deal with this?

Widget class:

 public class NewAppWidget extends AppWidgetProvider { SharedPreferences mSettings; void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { loadSettings(context); //загрузка данных из SP RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.template_widget); views.setTextViewText(R.id.appwidget_time_value, getDays(context)); RemoteViews views2 = new RemoteViews(context.getPackageName(), R.layout.template_widget); views2.setTextViewText(R.id.appwidget_count_value, getCount()); RemoteViews views3 = new RemoteViews(context.getPackageName(), R.layout.template_widget); views3.setTextViewText(R.id.appwidget_money_value, getMoney()); Intent intent = new Intent(context, MainActivity.class); PendingIntent pIntentMainActivity = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.widget, pIntentMainActivity); appWidgetManager.updateAppWidget(appWidgetId, views); appWidgetManager.updateAppWidget(appWidgetId, views2); appWidgetManager.updateAppWidget(appWidgetId, views3); } @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int appWidgetId : appWidgetIds) { updateAppWidget(context, appWidgetManager, appWidgetId); } } @Override public void onEnabled(Context context) { // Enter relevant functionality for when the first widget is created } @Override public void onDisabled(Context context) { // Enter relevant functionality for when the last widget is disabled } 

Provider

 <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:initialKeyguardLayout="@layout/template_widget" android:initialLayout="@layout/template_widget" android:minHeight="20dp" android:minWidth="120dp" android:resizeMode="horizontal" android:previewImage="@drawable/example_appwidget_preview" android:updatePeriodMillis="1800000" android:widgetCategory="home_screen"> </appwidget-provider> 
  • one
    And for what you get several times the object RemoteViews views, and then also for each cause an update. This is the same object. And don't forget to add the call to the parent method in onUpdate: super.onUpdate (context, appWidgetManager, appWidgetIds); - dubok79
  • Thanks, it seems to work as it should. Can you make a comment as an answer? - R1zen

1 answer 1

The object of the RemoteViews class to receive several times does not make sense, because it is the same.

It is also necessary to add a call to the parent method super.onUpdate(context, appWidgetManager, appWidgetIds);