【发布时间】:2013-12-28 18:39:57
【问题描述】:
我正在尝试在列表视图中启动一项新活动 onItemClick。
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view,
int position, long id) {
Intent intent = new Intent(ItemListActivity.this, ItemDetailActivity.class);
try {
intent.putExtra(MEMORY_ID, result.getJSONObject(position).getInt("id"));
} catch (JSONException e) {
e.printStackTrace();
}
intent.putExtra(LATITUDE, currentLocation.getLatitude());
intent.putExtra(LONGITUDE, currentLocation.getLongitude());
startActivity(intent);
}
});
当它下降到 startActivity(intent) 时,我可以通过调试器看到正确的值在意图中。但是,当我在 ItemDetailActivity 中执行 getIntent() 时,该意图没有值。 mMap 为空。
访问 extras 的代码是
Intent intent = getIntent();
// Create a new HttpClient and build GET request
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://128.61.107.111:56788/memories/view_specific/" +
intent.getStringExtra(ItemListActivity.MEMORY_ID) +
"?latitude=" + intent.getStringExtra(ItemListActivity.LATITUDE) +
"&longitude=" + intent.getStringExtra(ItemListActivity.LONGITUDE));
这里发生了什么?我没有抓住正确的意图吗?我的价值观是如何丢失的?
【问题讨论】:
-
当您
getExtras时会发生什么?可能是调试器的问题 -
显示您调用的活动 onCreate 函数...您的意思是 getIntent().getExtras() 吗?
-
还显示来自 ItemDetailActivity 的代码,您可以在其中获取额外内容。
-
getExtras 只是在我执行 getString() 时返回 null。我已经用获取附加功能的代码更新了问题。