Ste*_*fan 10 android widget android-pendingintent
我的Widget启动服务,服务更新3个LinearLayouts列表.
我想在每个LinearLayout上设置一个具有不同Extra的SetOnClickPeningIntent
但是,当我启动小部件并想要点击LinearLayouts时,只有最后一个是onclickable = /我不知道什么是错的.希望您能够帮助我.
RemoteViews remoteViews = new RemoteViews(getPackageName(),
R.layout.widget_layout);
for (int widgetId : appWidgetIds) {
int[] lls = { R.id.ll_con_1, R.id.ll_con_2, R.id.ll_con_3 };
for (int i = 0; i < jray.length(); i++) {
try {
JSONObject o = jray.getJSONObject(i);
//Onclick
if(i == 0)
{
Intent msg_intent = new Intent(getApplicationContext(), MSGsOpenMsg.class);
msg_intent.putExtra("messageid", o.getString("id"));
PendingIntent msg_pendingIntent = PendingIntent.getActivity(
getApplicationContext(), 0, msg_intent, Intent.FLAG_ACTIVITY_NEW_TASK);
remoteViews.setOnClickPendingIntent(R.id.ll_con_1, msg_pendingIntent);
}
else if(i == 1)
{
Intent msg_intent1 = new Intent(getApplicationContext(), MSGsOpenMsg.class);
msg_intent1.putExtra("messageid", o.getString("id"));
PendingIntent msg1_pendingIntent = PendingIntent.getActivity(
getApplicationContext(), 0, msg_intent1, Intent.FLAG_ACTIVITY_NEW_TASK);
remoteViews.setOnClickPendingIntent(R.id.ll_con_2, msg1_pendingIntent);
}
else if(i == 2)
{
Intent msg_intent = new Intent(getApplicationContext(), MSGsOpenMsg.class);
msg_intent.putExtra("messageid", o.getString("id"));
PendingIntent msg2_pendingIntent = PendingIntent.getActivity(
getApplicationContext(), 0, msg_intent, Intent.FLAG_ACTIVITY_NEW_TASK);
remoteViews.setOnClickPendingIntent(R.id.ll_con_3, msg2_pendingIntent);
}
} catch (JSONException e) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
Jer*_*rds 22
我有这个问题.这是因为Android试图将类似的PendingIntents崩溃为1,这有一些非常令人讨厌的后果.IE中较旧的意图在它们略有不同时被删除.我认为它们如何崩溃也存在一个错误,因为它与文档不匹配.(我很久以前遇到过这种情况,所以情况可能会发生变化.)
基本上我确保PendingIntent.getActivity中的requestCode参数对于每个UI项都是不同的.这样他们每个人都得到自己的PendingIntent并且永远不会发生碰撞.
我在这里有代码试图解决问题,但这有点浪费. http://code.google.com/p/futonic-mylocationwidget/source/browse/src/com/futonredemption/mylocation/Intents.java#35
我承认我的代码中的解决方案并不是最好的,但到目前为止似乎工作得很好.
| 归档时间: |
|
| 查看次数: |
2190 次 |
| 最近记录: |