Hey there.
So we have created settings activity in which we can now go and set the checkbooks.
The application to make a sound and prohibit when the checkbooks is unchecked.
And now we need to associate these settings with our shared preference file.
Let's go to court.
So this setting is associated with the value in the file using the key that we specified here in this
case enable sound.
And now we need to understand how we can access the file and where to do it and access to the file share
preferences is obtained using the preference manager.
We have already done this.
Whether you were to do it it needs to be done.
Let's look at the main activity and in the start method or click method which start that timer has the
own finished method which is called when our countdown timer finishes it's called and in their own finished
method we can check our setting.
Eve there is a checkmark in the checkbooks.
It means that the sound we have enabled.
And in this case we can run this code that reproduces this out.
That is we need here in on Finnish access to shared preferences let's write shared preferences shared
preferences assigns specified preference manager and specify method get default share preferences but
haven't to use it yet.
Using this method we get access to the file in which the value from that preference screen is written
that we created to view from the X symbol element preference screen.
And this value is placed in the default shared preference file to which we can be accessed which can
be accessed using the get default shared preferences method.
Further here it is necessary to indicate a context with we do it since we are inside are not anonymous
class so we can do this with get application context and then we need to check.
Well let's go loves this stuff for a bit of view.
Next we need to check what we have in this file.
We write the shared preferences get boolean.
In this case we have the value of true or false.
There is the check mark is in the checkbooks.
Then the value is true.
If it is not then the value is false.
And here we must specify this key that it's copied and pasted here and call must separate the default
value that will be set.
If the setting is not found in the shared preferences file let's set it to true by default so that the
sound is turned or further.
If we have this value true then we put this code here.
That is then we'll launch our media player turn on the sub.
Otherwise this will not happen.
Let's check now restart the application
so let's check what we have in the settings activity.
That sound is now enabled.
So when Start the sound should work let's say this time a start
everything is great the sound worked.
Now let's try to remove the sound
and saw the time again.
Huh.
We have not updated the interface.
Let's get to take a look.
Well of course reset time.
That method also called only one true set was called the reset timer.
From here we will reset the time either way no matter Drew here or false.
Let's restart again
let's check that water in said infectivity.
And as you see the checkbooks remains empty.
That is where store data in shared preferences.
And now let's try to test the functionality
excellent.
Everything has been updated.
And there is no sound.
Well let's say the sound again.
There is still the time
and everything works great.
We've done it.