【发布时间】:2012-04-03 20:49:49
【问题描述】:
如何从 AppWidget 启动活动?我想让用户能够编辑其设置。
【问题讨论】:
标签: android
如何从 AppWidget 启动活动?我想让用户能够编辑其设置。
【问题讨论】:
标签: android
所有 AppWidget 方法都有一个 Context:你可以使用它来创建一个 Intent 来启动你的 Activity。
编辑:严格来说,您甚至不需要上下文(只需创建一个 Intent,然后调用 startActivity)。
【讨论】:
您可以在 Internet 上找到很多示例,此示例非常感谢 Mark Murphy
https://github.com/commonsguy/cw-advandroid/tree/master/AppWidget
【讨论】:
你必须这样做:
Intent intent = new Intent(context, MainWidgetActivity.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 rv = new RemoteViews(context.getPackageName(), R.layout.appwidget);
rv.setOnClickPendingIntent(R.id.button, pendingIntent);
而 MainWidgetActivity.class 是您要启动的 Activity
【讨论】: