Hey there.
So how to save our text you when changing orientation.
Let's take a look at our own grade math up here.
We pass safe in some state or the Bondo class as a parameter.
This is the saved state or the object.
These are refers to the object of the main activity clause and it's state that is the state of our activity
in an object of class bundle.
You can store a value using key value pairs just as we saved these pairs in the intent and then in the
own create method from this object saved instance state of the object is used to extract data.
For these before extracting their data.
Of course we need to put the data in this object.
And this is done in the own say instance state method.
It is spelled almost almost the same and we must override this method.
We right on say in some state.
Here it is issued by the first press enter.
We are given a fair version with two parameters but we need one parameter.
In this case we will remove the second parameter.
Now here after calling their own safe instead method of the superclass we write the following code.
We need to extract from our text do you.
We have extracted the text we want to save and put it in this parameter that we pass in their own safe
for instance state method.
And this is all done as follows.
Our state puts string since we put the string there.
Then we need to specify a sum Key for example text to bundle.
For example and further we need to specify what we will put we will extract from our text through text
to get text and to string method.
That is we extract that text of all it takes two and put the string in our bundle of state.
Now we can extract our information in our own create method.
Well let's before we put all the text in our state in order to determine that this method worked on
say for instance state.
Let's put here the same code that we put in all the lifecycle methods
paste that here.
But here we are right for example on say for instance state.
Let's copy
and the same here.
And further in the create method after we have our text to bind we can check.
Right.
If CSA instance state not equals null then we can put in text to what we extract from safe and sound
state text to set text saved instance state get string and get string by these key
and now let's check out what could work.
And so our methods on great on START and on resume worked at the initial start.
Next less to the background on pause and on stop work then output and save for instance state.
Also worked.
And now let's change the orientation.
And as you can see.
Saves instance state method worked and our text was all saved in text 2.
If we go back everything also continues to work.
That is after the on post method when the activities post their own say in some state matter the school
in which all data is stored so that later it can be retrieved by the on create method.
And so we examined the first way to save data in Android using on safe instant state.
We learned how to PWD to the bundle of outstate object strings but besides strings are the primitive
types of data can be placed there.
Let's go into the search type Android bundle
go to the Android developer site and here in the methods you can see various PWD methods that can PWD.
For example data of types barred by Atari.
Cha cha Rei.
And so on.
We can even place to the bar though objects of our own class.
But to do this we need to implement the possible interface in this class.
If we click on it you see the public interface possible and we have to implement it in our class as
it is done here.
In the example public class my passable is created and it implements the passable interface.
And in this case we can put this class in the bundle.
Everything is fine but there is one thing.
The fact is that if we now exist our application and now run it again and then all the data disappears.
The fact is that on St. instance state saves data only during one user session.
That is if the application is closed then all data is lost.
What to do if we want to save data even after we closed the application.
We can then use the second method of saving data using shared preferences.
How about this.
I will discuss in the next video.