我有这个简单的小部件,当我点击它时,它应该打开我的活动,它工作,但它重新启动后不起作用.我必须删除然后再次将小部件添加到我的主屏幕,因为当我点击小部件小部件时没有响应并且不会打开我的活动.那问题出在哪里?
码:
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
for(int i=0; i
int appWidgetId = appWidgetIds[i];
context.startService(new Intent(context, WidgetService.class));
Intent intent = new Intent(context, WidgetDialog.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setOnClickPendingIntent(R.id.layout_widget, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
@Override
public void onEnabled(Context context){
context.startService(new Intent(context, WidgetService.class));
}
@Override
public void onDisabled(Context context){
context.stopService(new Intent(context, WidgetService.class));
}