我有這樣的代碼:意向不提取額外
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Log.i(TAG, "The id of the selected note is " + id);
Intent editNote = new Intent(this, TaskEditActivity.class);
editNote.putExtra(TasksDBAdapter.KEY_ID, id);
startActivityForResult(editNote, EDIT_TASK_REQUEST);
}
而這種代碼,獲取額外從不同的活動:
if (savedInstanceState != null) {
id = savedInstanceState.getLong(TasksDBAdapter.KEY_ID);
}
Log.i(TAG, "Id of note = " + id);
在第一代碼片段,logcat的說:The id of the selected note is 2
,但在第二個代碼片段中,Logcat說:Id of note = 0
。這裏發生了什麼?任何解決這個非常惱人的問題。
請看我的粗體解釋。 – 2010-08-03 16:45:09