我正在尝试创建一个每半小时更新一次的应用。并且目前正尝试在小部件点击上启动更多活动,但它无法正常工作
以下是我的provider.java类
public class Provider extends AppWidgetProvider {
public static void updateAppWidget(Context paramContext,
AppWidgetManager localAppWidgetManager, int i, String string) {
ComponentName thiswidget = new ComponentName(paramContext,
Provider.class);
AppWidgetManager manager = AppWidgetManager.getInstance(paramContext);
int[] allWidgetIds = manager.getAppWidgetIds(thiswidget);
for (int widgetId : allWidgetIds) {
Intent in = new Intent(paramContext, display_widget.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
paramContext, 0, in, 0);
RemoteViews remoteViews = new RemoteViews(
paramContext.getPackageName(), R.layout.main);
remoteViews.setOnClickPendingIntent(R.id.Main, pendingIntent);
localAppWidgetManager.updateAppWidget(widgetId, remoteViews);
}
}
public void onUpdate(Context paramContext,
AppWidgetManager paramAppWidgetManager, int[] paramArrayOfInt) {
int i = paramArrayOfInt.length;
for (int j = 0;; j++) {
if (j >= i) {
return;
}
int k = paramArrayOfInt[j];
updateAppWidget(paramContext, paramAppWidgetManager, k,
"soome string");
}
}
}
提前感谢.. :))
答案 0 :(得分:0)
尝试使用PendingIntent.FLAG_UPDATE_CURRENT
Intent intent = new Intent(paramContext, display_widget.class);
intent.setAction(ACTION_BUTTON);
PendingIntent pendingIntent = PendingIntent.getBroadcast(paramContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.widget_button, pendingIntent);