I have a search screen which can be launched from clicking on a "name" field of another screen.
If the user follows this workflow, I add an extra to the Intent's Extras called "search". This extra uses the text populating the "name" field as its value. When the search screen is created, that extra is used as a search parameter and a search is automatically launched for the user.
However, since Android destroys and recreates Activitys when the screen rotates, rotating the phone causes an auto-search again. Because of this, I'd like to remove the "search" extra from the Activity's Intent when the initial search is executed.
I've tried doing this like so:
Bundle extras = getIntent().getExtras(); if (extras != null) { if (extras.containsKey("search")) { mFilter.setText(extras.getString("search")); launchSearchThread(true); extras.remove("search"); } }
However, this isn't working. If I rotate the screen again, the "search" extra still exists in the Activity's Intent's Extras.
Any ideas?
We can start adding data into the Intent object, we use the method defined in the Intent class putExtra() or putExtras() to store certain data as a key value pair or Bundle data object. These key-value pairs are known as Extras in the sense we are talking about Intents.
putExtra("id".....), I would suggest, when it makes sense, using the current standard fields that can be used with putExtra(), i.e. Intent. EXTRA_something. A full list can be found at Intent (Android Developers).
The easiest way to do this would be to pass the session id to the signout activity in the Intent you're using to start the activity: Intent intent = new Intent(getBaseContext(), SignoutActivity. class); intent. putExtra("EXTRA_SESSION_ID", sessionId); startActivity(intent);
I have it working.
It appears getExtras() creates a copy of the Intent's extras.
If I use the following line, this works fine:
getIntent().removeExtra("search");
Source code of getExtras()
/** * Retrieves a map of extended data from the intent. * * @return the map of all extras previously added with putExtra(), * or null if none have been added. */ public Bundle getExtras() { return (mExtras != null) ? new Bundle(mExtras) : null; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With