Android Home screen Widget: RemoteViews setRemoteAdapter(…) method not working on API 11+

后端 未结 3 533
悲&欢浪女
悲&欢浪女 2021-02-06 03:09

So onUpdate method calls

remoteViews.setRemoteAdapter(id, R.id.listview, intent)

in order to apply an adapter to the listview in the widget.

<
3条回答
  •  情书的邮戳
    2021-02-06 03:57

    Weird, but found a solution. Android seems to be caching the intents you use in your onUpdate method. If you resend what seems to be the same intent, it won't perform as you'd expect.

    Solution: have a static iterating integer which you include as a param in the intent extras. It solved the problem for me.

    Intent intent = new Intent(context, WidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, currentWidgetId);
    intent.putExtra("random", randomNumber);
    randomNumber++;
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    

    Oh, Android...

提交回复
热议问题