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(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
對app widget控制項的具體操作事情在繼承appWidgetProvider的類的複寫方法onUpdate中實現,操作步驟如下:
1. 建立Intent
2. 建立PendingIntent,傳入Intent
3. 建立RemoteViews對象 RemoteViews remoteViews = new RemoteViews(String packageName, int layoutId);
第一個參數是包含需要設施的layout的包明,可以通過context.getPackageName獲得;第二個參數是布局檔案
4. 調用remoteViews.setOnClickPendingIntent(綁定處理器的控制項ID , PendingIntent對象)方法
5. 更新app widget , appWidgetManager.updateAppWidget(appWidgetIds[i] ,remoteViews對象)方法