私のAndoirdアプリケーションでは、以下のコードでエクストラを他のインテントに渡します:
Intent i = new Intent(getApplicationContext(), NoteDetail.class);
i.putExtra("note_id", note_id);
startActivityForResult(i, 100);
noteDetail で、次のコードでエクストラを取得します。
if (i.hasExtra(Key_NOTE_ID)) {
// Must Update the note
KEY_HAS_NOTE_ID = true;
noteId = i.getStringExtra(Key_NOTE_ID);
Log.i("Note Id is >>", noteId.toString());
ConnectionDetector cd = new ConnectionDetector(
getApplicationContext());
if (cd.isConnectedToInternet()) {
new GetNoteDetail().execute();
} else {
Toast.makeText(NoteDetail.this,
R.string.not_connected_to_internet, Toast.LENGTH_SHORT)
.show();
}
}
アプリケーションは正しく機能し、携帯電話の戻るボタンを押して前のアクティビティに戻るまで、エクストラは正しく送受信されます。もう一度、noteDetail ボタンを押して noteDetail アクティビティに移動すると、前の note_id が残っており、明確ではありません。ユーザーが携帯電話の戻るボタンを押したときにエクストラをクリアしたい。