我的小部件上有2个按钮
我已经为这两个添加了putExtra
个不同的布尔标志
我正在尝试解析主要活动中的getExtra
但是当我点击它们时,它们完全相同(这不是我所期待的)。
看下面的代码,我做错了什么?
mainActivity
@Override
protected void onNewIntent(Intent intent) {
//called when the activity is relaunched by a new intent
setIntent(intent);
super.onNewIntent(intent);
}
@Override
public void onResume() {
super.onResume();
Intent testI = getIntent();
Bundle test = testI.getExtras();
if (test != null) {
boolean select = test.getBoolean("selectcontact",false);
if (select == true) {
pickContact();
}
}
}
来自AppWidgetProvider
(onUpdate
函数)
Intent mainIntent = new Intent(ctxt, MainActivity.class);
Bundle bundle = new Bundle();
bundle.putBoolean("selectcontact", true);
mainIntent.putExtras(bundle);
PendingIntent pendingIntent = PendingIntent.getActivity(ctxt, 0, mainIntent, 0);
widget.setOnClickPendingIntent(R.id.buttonAddwidget, pendingIntent);
Intent mainIntentE = new Intent(ctxt, MainActivity.class);
PendingIntent pendingIntentE = PendingIntent.getActivity(ctxt, 0, mainIntentE, 0);
widget.setOnClickPendingIntent(R.id.buttonEditwidget, pendingIntentE);
答案 0 :(得分:0)
// replace this code
@Override
public void onResume() {
super.onResume();
Intent testI = getIntent();
Bundle test = testI.getExtras();
if (test.getBoolean("selectcontact",false)) {
pickContact();
}
}
答案 1 :(得分:0)
对于2个意图,您使用相同的ID。 尝试使用不同的:
PendingIntent pendingIntent = PendingIntent.getActivity(ctxt, 0, mainIntent, 0);
PendingIntent pendingIntentE = PendingIntent.getActivity(ctxt, 1, mainIntentE, 0);