Android – Is the intent preserved during activity recreation?-ThrowExceptions

Exception or error:

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.

How to solve:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *