[英]Launching an activity from an AppWidget
How do i launch an activity from an AppWidget? 如何从AppWidget启动活动? I want to give the user the ability to edit its settings.
我想让用户能够编辑其设置。
All the AppWidget methods have a Context: you can use that to create an Intent to launch your Activity. 所有AppWidget方法都有一个上下文:您可以使用它来创建一个Intent以启动您的Activity。
EDIT: strictly speaking, you don't even need the Context (just create an Intent and then call startActivity
). 编辑:严格来说,您甚至不需要Context(只需创建一个Intent,然后调用
startActivity
)。
you can find a lot of examples around the internet this example is excellent courtesy of Mark Murphy 您可以在互联网上找到很多示例,此示例非常感谢Mark Murphy
https://github.com/commonsguy/cw-advandroid/tree/master/AppWidget https://github.com/commonsguy/cw-advandroid/tree/master/AppWidget
You have to do something like this: 您必须执行以下操作:
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);
while MainWidgetActivity.class is the Activity you want to launch 而MainWidgetActivity.class是您要启动的活动
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.