 Hey guys, it's MJ the student actually and I want to show you quickly how you can save a variable So I've got this little poker game that I've made and I'm going to be showing some videos on how I did it But what I want to show in this video is how to save the amount of tokens that you have Because very important that if someone had to say leave the app that they can come back And you know, they still have the same amount of tokens So to do this on Android first thing you need to do is you need to write this line of code Public static final string prefs name equals my press file So what you're doing here is you're creating a file on which to save things Then what you want to do is you want to go where you have the the protected void on create bundle save instance state So you want to get into this method here and you want to create something known as a shared preference and You can see I'm saving four variables one of them is the tokens and then the other three are used for people to bike by tokens But yeah, we just need to go through the first one and you want to write this line of code shared preference settings equals get shared preference and then you're gonna be referencing that press name and The very first slot that you're gonna be using. Okay, so that's for settings there What I also like to do is I like to call up. So when the game starts it's saying, okay, let's set the coins According to what is saved in this file So this as soon as the person uploads the app, they're saying, okay, I have this amount of tokens So we also want to state that in the on create method for your app You might do it a little bit differently But that's where I've put it and then you can see I'm setting the text view to show me how many coins I have But now let's say somebody comes in they buys by some coins I want that the amount of coins to be saved So don't worry about the method that I've got those saved in But what it's happening is let's say the person puts in a credit code I say, okay, their coins increases by 500 I now need to save that the coins have increased by 500 So I'm gonna go shared preference settings equals get shared preference pref name just like how I did before I'm gonna say shared preference dot editor Equal settings dot edit then I'm gonna put the coins Into the editor and then I'm gonna click this thing called commit You can see my Android studio is telling me to rather apply it and then you know just hold on to it But I actually want to commit that value so that if the app ever crashes in the state the person has got their 500 tokens which they have purchased and That's basically it. So this is the code that you want to do to save the information Remember right at the top This is the information that you want to use to create the storage and then this is something that you'll use to Recall the storage and remember just to create your storage At the top here and there we go That's how you use shared preferences in Android studio to save Variables for your app that you can then use at a later stage if your app closes Like I said, my app is called smart poker There will be a link in the description below feel free to download it and have some fun with it Thanks guys so much for watching and subscribe because I'm gonna be posting quite a few Programming videos. Cheers