android之app widget(二)
PendingIntent:
//创建PendingIntent的方法:
getActivity(Context context,int requestCode,Intent intent,int flags) //启动一个Activity
getBroadcast(Context context,int requestCode,Intent intent,int flags) //发送一个广播
getService(Context context,int requestCode,Intent intent,int flags) //启动一个服务
RemoteView:所表示的对象运行在不同的进程当中
//调用app widget按钮的方法,使用以下的监听
remoteViews.setOnClickPendingIntent(控件ID , pendingIntent方法)
onUpdate(Contextcontext,AppWidgetManagerappWidgetManager, int[] appWidgetIds)
对app widget控件的具体操作事情在继承appWidgetProvider的类的复写方法onUpdate中实现,操作步骤如下:
1. 创建Intent
2. 创建PendingIntent,传入Intent
3. 创建RemoteViews对象RemoteViewsremoteViews = newRemoteViews(StringpackageName, int layoutId);
第一个参数是包含需要设施的layout的包明,可以通过context.getPackageName获得;第二个参数是布局文件
4. 调用remoteViews.setOnClickPendingIntent(绑定处理器的控件ID , PendingIntent对象)方法
5. 更新app widget , appWidgetManager.updateAppWidget(appWidgetIds[i],remoteViews对象)方法
更多相关文章
- Android 7.0以上和7.0以下获取USB,sdcard路径的方法
- android 图片处理方法(整理)
- Android 方法调用堆栈信息显示
- Android查看电池电量的方法(基于BroadcastReceiver)
- android 判断当前线程是不是主线程的几种方法
- Android httpClient Get&Post方法
- Android 给textview添加下划线的一种方法(可复用)
- Android获取系统内核版本的方法