Appwidget widget list rows not updating or loading after the Marshmallow update

I have a widget application that runs Android Lollipop or a lower OS without problems. When I updated my connection 5 in Marshmallow (android 6.0), I understand that my widget had a problem loading a custom list of strings. The widget has a dynamic textView and a dynamic listView. textView works fine; but there is no hope for listView row items. When I add a widget, the lines are stuck in the loading phase. This exact same code works on Lollipop or lower devices, but not on Marshmallow. I believe that Marshmallow is causing a problem that I have not yet been able to find. I hope someone shows me what I'm doing wrong and help me solve this problem. I appreciate any help. Thank you

WidgetProvider.class:

@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { System.out.println("WidgetProvider.onUpdate()"); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final boolean isMaviKart = MainUtils.getCardType(context).equals(Constants.CARD_TYPE_MAVI); try { //set widget id ComponentName thisWidget = new ComponentName(context, WidgetProvider.class); int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget); MainUtils.setWidgetID(prefs, allWidgetIds[allWidgetIds.length - 1]); for (int i = 0; i < appWidgetIds.length; i++) { Intent intentService = new Intent(context, WidgetService.class); intentService.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); intentService.setData(Uri.parse(intentService.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget); widget.setRemoteAdapter(appWidgetIds[i], R.id.list_view, intentService); Intent clickIntent = new Intent(context, MainActivity.class); PendingIntent clickPI = PendingIntent.getActivity(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); widget.setPendingIntentTemplate(R.id.list_view, clickPI); if (isMaviKart) { widget.setTextViewText(R.id.kalanPara, String.valueOf(MainUtils.getTokenPass(prefs))); widget.setTextViewText(R.id.currency_tl, " GeรงiลŸ"); } else { widget.setTextViewText(R.id.kalanPara, String.valueOf(MainUtils.getTotalMoney(prefs))); widget.setTextViewText(R.id.currency_tl, " TL"); } appWidgetManager.updateAppWidget(appWidgetIds[i], widget); } } catch (Exception e) { e.printStackTrace(); Toast.makeText(context, context.getResources().getString(R.string.error_occured), Toast.LENGTH_SHORT).show(); } super.onUpdate(context, appWidgetManager, appWidgetIds); } @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); System.out.println("WidgetProvider.onReceive()"); String key = intent.getStringExtra(Constants.EXTRA); if (key != null) Log.e("TEST", key); } 

WidgetViewsFactory.class:

 @Override public RemoteViews getViewAt(int position) { Intent intent = new Intent(); Bundle extras = new Bundle(); rowButton = context.getResources().getIdentifier("widget_button","id", context.getPackageName()); rowText = context.getResources().getIdentifier("widget_textview","id", context.getPackageName()); RemoteViews row = new RemoteViews(context.getPackageName(), R.layout.row); // set BUTTON NAMES row.setTextViewText(rowButton, getFeeTypes(position)); // simple rows: configureRowsInListview(row, position, context.getResources().getColor(R.color.DeepSkyBlue), View.VISIBLE); extras.putString(Constants.EXTRA, getEventKey(position)); intent.putExtras(extras); row.setOnClickFillInIntent(rowButton, intent); row.setOnClickFillInIntent(rowText, intent); return row; } 

WidgetService.class:

 public class WidgetService extends RemoteViewsService { @Override public RemoteViewsFactory onGetViewFactory(Intent intent) { return(new WidgetViewsFactory(this.getApplicationContext())); } } 

MainActivity.class: (keyWord returns null for Marshmallow)

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); prefs = PreferenceManager.getDefaultSharedPreferences(this); String keyWord = getIntent().getStringExtra(Constants.EXTRA); if (keyWord == null) { keyWord = "null"; Log.e("onCreate() ", "No data Arrived yet!"); } } private void updateWidgetScreen(String updateData, String currencyType) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget); ComponentName thisWidget = new ComponentName(this, WidgetProvider.class); remoteViews.setTextViewText(R.id.kalanPara, updateData); remoteViews.setTextViewText(R.id.currency_tl, currencyType); Intent intent = new Intent(this, WidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, MainUtils.getWidgetID(prefs)); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(MainUtils.getWidgetID(prefs), R.id.list_view, intent); Intent clickIntent = new Intent(this, MainActivity.class); PendingIntent clickPI = PendingIntent.getActivity(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setPendingIntentTemplate(R.id.list_view, clickPI); appWidgetManager.updateAppWidget(thisWidget, remoteViews); Log.e("updateWidgetScreen", updateData+" updateData - widgetid: "+ MainUtils.getWidgetID(prefs)); } 

Problem with ListView Row: enter image description here

+7
android android-6.0-marshmallow android-appwidget android-widget appwidgetprovider
source share
1 answer

I found the mistake I made. I had a custom listview with a button with the android:style/Widget.Material.Button . When I removed the Button style, it fixed my problem.

  <Button android:id="@+id/widget_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="Button" android:layout_marginRight="10dp" android:gravity="center" android:padding="8dp" android:textColor="@color/White" **style="@style/MaterialButton"** /> <style name="MaterialButton" parent="android:style/Widget.Material.Button"> <item name="android:background">@drawable/raised_button_background</item> </style> 
0
source share

All Articles