【问题标题】:Launching an activity from an AppWidget从 AppWidget 启动 Activity
【发布时间】:2012-04-03 20:49:49
【问题描述】:

如何从 AppWidget 启动活动?我想让用户能够编辑其设置。

【问题讨论】:

    标签: android


    【解决方案1】:

    所有 AppWidget 方法都有一个 Context:你可以使用它来创建一个 Intent 来启动你的 Activity。

    编辑:严格来说,您甚至不需要上下文(只需创建一个 Intent,然后调用 startActivity)。

    【讨论】:

      【解决方案2】:

      您可以在 Internet 上找到很多示例,此示例非常感谢 Mark Murphy

      https://github.com/commonsguy/cw-advandroid/tree/master/AppWidget

      【讨论】:

        【解决方案3】:

        你必须这样做:

        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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-02-01
          • 2012-01-18
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多