1.什么是PendingIntent
(1)创建PendingIntent的方法
a.getActivity(Content content,int requestCode,Intent intent,int flage);
b.getBoardcast(Content content,int requestCode,Intent intent,int flage);
c.getService(Content content,int requestCode,Intent intent,int flage);
2.RemoteViews的作用
(1)RemoteViews对象表示了一系列的View对象
(2)RemoteViews所表示的对象运行在另外一个线程当中
3.在App Widget当中使用控件
(1)在example_appwidget.xml中添加一个Button
(2)为Button绑定处理器
(3)修改ExampleAppWidgetProvider的onUpdate()方法
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
for(int i=0;i<appWidgetIds.length;i++)
{
//跳转
Intent intent=new Intent(context,TargetActivity.class);
PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews remoteViews=new RemoteViews(context.getPackageName(), R.layout.example_appwidget);
//为按钮绑定事件处理器(第一个参数用来指定被绑定处理器 的控件的ID)
//第二个参数用来指定事件发生时,哪个PendingIntent将会执行
remoteViews.setOnClickPendingIntent(R.id.widgetButtonId, pendingIntent);
//更新AppWidget(第一个参数用于指定被更新AppWidget的ID)
appWidgetManager.updateAppWidget(appWidgetIds[i], remoteViews);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}