我有一个布局有两个按钮的小部件。我的代码如下,
public void onReceive(Context context, Intent i) {
AppWidgetManager mgr = AppWidgetManager.getInstance(context);
Intent intent = new Intent(context, Activity1.class);
PendingIntent pendingLayout = PendingIntent.getActivity(context, 0, intent, 0);
Intent searchIntent = new Intent(context, Activity2.class);
PendingIntent searchPendingLayout = PendingIntent.getActivity(context, 0, searchIntent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.searchwidget);
views.setOnClickPendingIntent(R.id.widgetbutton, pendingLayout);
views.setOnClickPendingIntent(R.id.widgetsearch, searchPendingLayout);
ComponentName comp = new ComponentName(context,
RecentTaskWidget.class.getName());
mgr.updateAppWidget(comp, views);
}
widgetbutton 和 widgetsearch 是布局中的两个视图。我从 remoteviews 对象中获取相应的视图,并将挂起的布局添加到每个视图中。但是,活动尚未开始。代码有什么问题吗?
谢谢!