I am building an android application, and would like to ask if the intent that started an activity (which is reachable via the getIntent () method) is saved / preserved during activity recreation such as a device orientation, or simply the fact that android can erase the application state if it is in the background and rebuild it (if it is low on memory) ?
This is a quick example that illustrates the question :
The application launches activity A. Then the user clicks on a button that starts a new activity B. Activity A has sent to activity B a string X with the value Hello via the intent (using the putExtra method).
In activity B, I can retrieve the content of string X by retrieving the intent (via the getIntent () method) and then retrieving the string content (via the getStringExtra method).
Will I still be able to retrieve the extra string from intent, or even the intent itself if the activity is recreated due to device rotation, ... ?
Or should I save the extra string in the onSaveInstanceState method ?
I have tried the device rotation scenario, and the intent (along with the extra string) are always accessible.
Activity is a UI component which you see on your screen. An Intent is a message object which is used to request an action from the same/different app component.
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);
Will I still be able to retrieve the extra string from intent, or even the intent itself if the activity is recreated due to device rotation
Yes. You will have the same Intent
(or, at least, a copy of the Intent
) after the configuration change as you had before the configuration change.
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