Hi everyone in this directory all of you are going to go ahead and create another Android application.
So just click on this.
Start in your Android studio project and for the name of our application name as you can see here just
type in here app 50.
OK so let me actually delete this name here app 50 and here click on next.
And here are the minimum STK choose AP is 16 Android 4.1 jelly bean.
And then click on next and here choose empty activity next and he can finish.
So now as you can see our application is actually created.
So let's actually get double click on the rest folder here and then double click on the layout folder
and here's double double click on this activity underline made that example.
So here as you can see this is the user interface of our application here.
So just select this hello world takes you here and then press on delete key on your keyboard.
And now let's say you did write a linearly or two vertical at the center of this relative lay out and
then let's actually find the check box which it has you can see here we have this checkbox component
here inside these widgets folder.
So just select it and put it at the center of this linearly 20 call and double click on it.
So as you can see here the text is new checkbox and the IDs checkbox.
And I think that's enough for this tutorial so you can actually leave it as default.
OK.
So I'll just press enter on your keyboard and now there's actually to go inside is main activity that
double file here and here let's actually declare our checkbox object so here can just type in checkbox
and the name of my checkbox is going to be checkbox.
Assignment operator and here I'm going to recast this object to a checkbox object find view by OED or
that ID that checkbox.
OK so here as you can see I actually created this checkbox object inside my class.
OK.
You can actually do this here inside your class or you can actually only declare your checkbox object
in your class and in an instant sheet your checkbox object inside your uncreate Smurfette.
So here I have just been checkbox here.
Assignment operator and then I can actually cast this object to a checkbox object find view by id odd
that Id dot checkbooks.
OK.
And at the end the end of your statement you need to put a semicolon here.
So now I want to talk about shared preferences in Android.
So first of all let's actually run our project now and see what happens.
So now as you can see our application is running on the emulator here.
So if I click on this checkbox here let's see what happens.
And now as you can see the search box is actually checked.
And if I click on the tick box here again.
Now this checkbox is actually checked off.
Now I haven't actually check check this checkbox here.
And then when I actually click on this back button here soon as I can see the undestroyed if it is actually
called and our application is actually no longer in the memory.
And if we want to actually open our application again here as you can see now as you can see that as
you can see here this check box is actually the checked of in the last time that they actually opened
this application.
I actually checked just this checkbox.
OK.
And I want to actually save this state.
So I want to actually check this checkbox and when I actually click on the back button and the application
is actually destroyed inside our memory when I go back to my application of and I actually open my application
again.
I've gone this state here to be saved.
I want this state to be saved and I want to access that state.
So how I can do that.
And that's the purpose of this tutorial in this tutorial.
Want to talk about shared preferences.
In order to actually save your save the status of your application.
So first of all you need to actually make this checkbox here are listening to the police of the user.
So I can't just type in checkbox that set on checked change listener here.
So inside the practices we need to specify the context.
So here I can just type in main activity that this.
OK.
And now we need to actually implement the compound button that unchecked change to listener interface.
So here at the top after this piece of code here extends app compact activity implements and here the
Kansas IPN compound what of it chapiters see compound button that uncheck change listen and with Capitol
all unchecked change listen.
OK.
So here I have this interface.
So we need to actually implement the abstract Smurfette that is inside of this interface in our main
activity class.
So here I can just type in unchecked chained here as you can see this is that this is the method that
is inside of this interface and we are actually implementing that method in our on main activity class.
So whenever the user clicks on this checkbox here as you can see when the user checks or uncheck this
checkbox here or this effort here unchecked change is going to be called OK.
So now as you can see I can just type in if it is checked and this means that if this checkbox here
is actually checked.
So now when I truly create these curly braces here.
So inside these curly braces are you going to actually change this text of this check checkbox here.
OK.
I want to just put the text the checkbox is checked here in in place of this text view takes a view
here OK.
So here I can as you can see I have this checkbox here in my main activity so I can refer to the name
of this checkbox object in my on Cheikh change method so I can just type in checkbox that set text.
And as you can see I can actually change the text of this checkbox then this checkbox is actually checked.
So you say the prentices I can't just put in two double quotes and I can't just type in the checkbox
is checked OK.
And here I actually create an else statement and this means that if this checkbox is actually not checked
ok then I'm going to actually change the text of this text checkbox to this text box is not checked.
So here I can't just refer to the name of this object checkbox that said text and inside Apprentice's
Argento's type in the checkbox
is not checked.
OK so now let's run our project and see what happens when I take or on this checkbooks here.
So as I can say now the application is running on this emulator.
So now I want to check this checkbox.
And as against can heal this checkbox is actually checked and the text of this takes checkbox is actually
the checkbox is checked OK.
So let's actually uncheck this checkbox and that takes these.
The checkbox is not checked OK.
So hopefully that makes sense and want to actually save this state.
For example I can actually check this checkbox over want to save this state in memory.
So when I actually click on dispatch button and the application destroys in memory and when I go back
to my application and open my application I want that state to be saved.
OK.
And as you can see that state is not saved at the moment.
So what's the solution.
The solution is preferences in Android.
So in order to do that first of all we need to actually override the unpause Merfeld on pause Meffert
that is inside of the Android lifecycle on past Meffert and the on resume if.
OK.