Android 从小部件启动活动

Android 从小部件启动活动,android,android-intent,widget,Android,Android Intent,Widget,因此,我已经看到了许多关于如何从android小部件启动活动的解决方案,现在我的问题是,我是否需要在清单中声明要启动的活动?我有一个带有布局的活动,我有一个带有挂起意图的小部件提供程序,当我点击一个按钮时会触发,但它不会带我去活动。这是我的密码 final int N = appWidgetIds.length; // Perform this loop procedure for each App Widget that belongs to this provider fo

因此,我已经看到了许多关于如何从android小部件启动活动的解决方案,现在我的问题是,我是否需要在清单中声明要启动的活动?我有一个带有布局的活动,我有一个带有挂起意图的小部件提供程序,当我点击一个按钮时会触发,但它不会带我去活动。这是我的密码

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, WidgetActivity.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.widget_layout);
        views.setOnClickPendingIntent(R.id.button1, pendingIntent);

        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
final int N=appWidgetIds.length;
//对属于此提供商的每个应用程序小部件执行此循环过程

对于(int i=0;i您需要在清单中定义您的活动。例如

<activity android:name="org.achartengine.GraphicalActivity" />

创建意图后。

我在logcat上没有发现任何错误,我在清单上也有活动,但它没有任何与之相关的意图。我可能错过了什么?试试intent.addFlags(intent.FLAG\u activity\u NEW\u TASK);在你创建了你的意图之后。什么都没有发生,我绝望了。我将待定的意图分配给了布局上的一个按钮,y只是坐在那里,我单击它,什么都没有。。。。
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);