【发布时间】:2014-05-31 04:08:37
【问题描述】:
我使用小部件帮助用户显示重要数据并从小部件打开应用程序。
我的小部件有 3 个按钮,当用户点击不同的按钮时,我需要打开应用程序。 我需要打开相同的活动,但根据用户单击的按钮使用不同的数据。我有意传递不同的额外内容
例如
Ist 按钮我将用户名设置为“Ranjith”
对于第二个按钮,我将用户名设置为“Thomas”
对于第三个按钮“Rixon”
但当活动打开时,它总是显示 Rixon 第三个。
logIntent= new Intent(context, MainActivity.class);
earnIntent=new Intent(context, MainActivity.class);
connectIntent=new Intent(context, MainActivity.class);
logIntent.putExtra("user_name", "Ranjith");
connectIntent.putExtra("user_name", "Thomas");
earnIntent.putExtra("user_name", "Rixon");
}
remoteViews.setOnClickPendingIntent(R.id.bottom_of_widget_log,createPendingIntent(context, 0, logIntent));
remoteViews.setOnClickPendingIntent(R.id.bottom_of_widget_earn, createPendingIntent(context, 1, earnIntent));
remoteViews.setOnClickPendingIntent(R.id.bottom_of_widget_connect, createPendingIntent(context, 2, connectIntent));
AppWidgetManager manager = AppWidgetManager.getInstance(context) ;
manager .updateAppWidget(thisWidget, remoteViews);
【问题讨论】:
-
发布你的代码
createPendingIntent()
标签: android android-activity android-widget android-pendingintent