Glide 入门到精通之十——加载图片到通知栏和应用小部件中( 二 )


来看看一个简单的实例:
public class FSAppWidgetProvider extends AppWidgetProvider {private AppWidgetTarget appWidgetTarget;@Overridepublic void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.custom_view_futurestudio);appWidgetTarget = new AppWidgetTarget( context, rv, R.id.custom_view_image, appWidgetIds );Glide.with( context.getApplicationContext() ) // safer!.load( GlideExampleActivity.eatFoodyImages[3] ).asBitmap().into( appWidgetTarget );pushWidgetUpdate(context, rv);}public static void pushWidgetUpdate(Context context, RemoteViews rv) {ComponentName myWidget = new ComponentName(context, FSAppWidgetProvider.class);AppWidgetManager manager = AppWidgetManager.getInstance(context);manager.updateAppWidget(myWidget, rv);}}
几行重要的代码声明了对象以及 Glide 的建造者 。这里的好处是,你不需要去定制并重写任何方法 。Glide 都自动帮你做好了 。太棒了!