gpt4 book ai didi

android - 当 Android 小部件 RemoteViewService 被销毁时

转载 作者:行者123 更新时间:2023-11-29 20:32:35 24 4
gpt4 key购买 nike

我正在研究 Widget包含 ListView作为集合。我已经创建了 RemoteViewService 的具体实现并实现 onGetViewFactory()方法提供RemoteViewsService.RemoteViewsFactory具体实现。

我将服务设置为 RemoteView使用以下代码:

Intent intent= new Intent();
intent.setAction("remote_service");
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
intent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
remoteViews.setRemoteAdapter(R.id.widget_list, intent);

我在 RemoteViewFactory 的具体实现中保存 List 对象.

查询步骤:

  • 在主屏幕上放置了小部件。
  • 这会导致创建 RemoteViewFactory。
  • 将设备置于 sleep 模式。
  • 现在将 RemoteViewService 销毁导致 RemoteViewFactory垃圾收集的具体实现,因此 List<String>对象销毁。

请推荐?

最佳答案

RemoteViewsServiceAppWidgetProvider 一样,不会永远存在。您的 RemoteViewsService 在其 onGetViewFactory() 方法中应该返回您的 RemoteViewsFactory 的新实例。 RemoteViewsFactory 所需的任何数据都需要持久化(例如,SQLiteDatabase)并根据需要检索。

关于android - 当 Android 小部件 RemoteViewService 被销毁时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31745314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com