【问题标题】:Pass variable/intent to an activity when launched from a Widget从小部件启动时将变量/意图传递给活动
【发布时间】:2010-12-21 23:30:06
【问题描述】:

目前在我的应用程序的一个活动中,我可以调用另一个活动并通过以下方式将变量传递给它:

Intent myIntent = new Intent(parentView.getContext(), ShowStations.class);
myIntent.putExtra("stationName", stations[position].StationName);
startActivity(myIntent);

这很好用,但现在我希望能够从我的小部件中做同样的事情。目前,此代码适用于从我的小部件启动特定活动:

Intent WidgetIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("grell.com", "grell.com.FavStations"));
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, WidgetIntent, 0);
    updateViews.setOnClickPendingIntent(R.id.widget_main, pendingIntent);

所以现在我想知道如何启动与第一个示例中所示相同的活动,但也可以通过“stationName”变量。

任何帮助将不胜感激。

干杯

【问题讨论】:

    标签: android android-activity android-widget


    【解决方案1】:
    Intent widgetIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("grell.com", "grell.com.FavStations"));  
    widgetIntent.putExtra("stationName", stations[position].StationName);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, widgetIntent, 0);    
    updateViews.setOnClickPendingIntent(R.id.widget_main, pendingIntent);
    

    检查上面的代码是否适合你。

    【讨论】:

    • 不幸的是没有运气。似乎可能必须以某种方式以待定意图完成??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-07
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    相关资源
    最近更新 更多