【发布时间】:2017-06-05 12:52:38
【问题描述】:
我在点击底部栏时在活动中调用片段。 该片段在片段中有以下消息对象。
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
Intent moreSelectionIntent = new Intent(getActivity(), MainActivity.class);
moreSelectionIntent.putExtra("selection",Integer.toString(position));
PendingIntent pendingIntent = PendingIntent.getActivity(getActivity().getApplicationContext(), 0, moreSelectionIntent, PendingIntent.FLAG_UPDATE_CURRENT);
} `
片段调用activity并传递PendingIntent。当我使用下面的代码从意图中获取字符串时,我在活动中得到 NULL 下面是activity中的一段代码
Intent i = this.getIntent();
Log.i(TAG, "intenet------->"+i);
String moreSelection = i.getExtras().getString("selection");
Log.i(TAG, "moreSelection Bundle------->"+moreSelection);
if(moreSelection!=null)
{ System.out.println("message"+moreSelection);}
【问题讨论】:
-
分享您的完整代码,您是否按照您的意图添加字符串..
-
感谢您在 stackoverflow 中鼓励其他人。我已经更新了完整的代码。
标签: android android-fragments android-intent android-activity