我正在开发我的第一个应用程序小部件。 除了一件事情外,一切都很好。我无法弄清楚如何在RemoteViewsFactroy的getViewAt()方法中使用Glide将图像加载到ImageView中。我总是会遇到错误,因为我必须在主线程中运行into(AppWidgetTarget),但我无法从RemoteViewsFactory调用new Handler(Looper.getMainLooper())。
我正在开发我的第一个应用程序小部件。 除了一件事情外,一切都很好。我无法弄清楚如何在RemoteViewsFactroy的getViewAt()方法中使用Glide将图像加载到ImageView中。我总是会遇到错误,因为我必须在主线程中运行into(AppWidgetTarget),但我无法从RemoteViewsFactory调用new Handler(Looper.getMainLooper())。
onUpdate()
中创建一个新的 AppWidgetTarget,将其传递给 RemoteViews
对象、图像视图的 ID 和 appwidgetId,然后以与应用程序中 ImageView 相同的方式调用 Glide。 appWidgetTarget = new AppWidgetTarget( context, rv, R.id.custom_view_image, appWidgetIds );
Glide
.with( context.getApplicationContext() ) // safer!
.load( GlideExampleActivity.eatFoodyImages[3] )
.asBitmap()
.into( appWidgetTarget );