Reputation: 784
In my Andoird application, i pass extras to other intent by below code :
Intent i = new Intent(getApplicationContext(), NoteDetail.class);
i.putExtra("note_id", note_id);
startActivityForResult(i, 100);
in noteDetail, get extras by this code :
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();
}
}
Application work correctly and extras pass and receive correctly until press back button on mobile phone and back to previous activity. again when i press the noteDetail button and go to noteDetail activity the previous note_id has remained and not clear. i want to clear extras when user press back button on mobile phone.
Upvotes: 1
Views: 543
Reputation: 5322
In onPause()
use:
if (getIntent().hasExtra(Key_NOTE_ID)) getIntent().removeExtra(Key_NOTE_ID);
Upvotes: 2