我希望能够点击小部件并启动对话框。我已经阅读了官方文档和一些非官方的资料。最初我想启动一个新的活动,但即使如此也失败了。我在Logcat中看到了以下内容,但实际上我什么都看不到。
11-14 21:28:47.929: INFO/ActivityManager(116): Starting: Intent { flg=0x10000000 cmp=com.android.app/.Execute bnds=[179,89][300,160] } from pid -1
我猜以上内容的意思是:意图已经传递了...但实际上活动并没有启动。应该启动的活动是普通活动吗?
使用的代码如下:
public class ExampleAppWidgetProvider extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch ExampleActivity
Intent intent = new Intent(context, ExampleActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider_layout);
views.setOnClickPendingIntent(R.id.button, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
有什么想法吗?