Today we will learn how to use Shared Preferences in Android to store data. We will use a SharedPreferences.Editor to save Strings and Booleans, but you can also save other data types like Integers, Floats or Long variables.

Example code:

____________________
❗ Subscribe to the channel:

⏯ Watch more tutorials:

⭐ Become a channel member for exclusive tutorials and other perks:

㊙ Help translating the videos:

💚 Support the content:

💬 Join the Discord chat:

🎧 Audiobooks and podcasts for programmers:

👶 How to get started with Android development:

📣 Follow Coding in Flow on social media:

Facebook:

Instagram:

Twitter:

Blog:

Nguồn:https://u-os.org/

Xem Thêm Bài Viết Khác:https://u-os.org/cong-nghe

Author

33 Comments

  1. Coding in Flow Reply

    * * *
    I added a link to the code for this video into the description!
    * * *

  2. Partha Wijaya Reply

    may I ask what is the button for? I tried to make without it but it doesn't work

  3. Alexander K Reply

    I have been enjoying your tutorials while learning android development for my job. So far i have mostly done ios. I am always happy when i see your videos show up when i'm querying youtube. Thank you for this! Very clear, to the point, and with excellent tempo and editing. THIS is how coding tutorials should be done! Well done!

  4. Alter Arrow Reply

    Dude, thanks for the the help! One of the few android videos on you tube where you go slow and we can understand what you are saying.

  5. Mustafa Abouelwafa Reply

    brother i am a little bit confused because i have no save button and no switch no edit text
    i have only counter button with value on it and rest button

    what i need to do is to save the counter value when i close the app and reopen it.
    i am following your instruction but i got stuck when you started talking about the save data button –
    please tell me how to fix it and thanks a lot in advance.

  6. Kristián Dudák Reply

    Very helpful, was searching through the whole web just to find this. Big thanks man.

  7. Riley Barringer Reply

    ALL of your videos have been extremely helpful; I am forever grateful.

  8. JKwebers Land Reply

    Nice tutorial but how to save selected item of spinner in sharedpreferences??

  9. Ashish Ucheniya Reply

    sir, can we save single custom class object using your above given method ?

  10. prajakta kadam Reply

    Hello sir i am new in android programming our video is so helpful for me.
    Also i required the source code for calculate distance between two places

  11. So sharedPreferences are like a table of info saved on your device?

  12. farooq shaik Reply

    Hi, will this work for dropdowns too ? I have 3 dropdown combination and I want to save the combination when the user next time opens the app

  13. Malick Awais Reply

    Sir please help me!

    How to put and retrieve double value in share preferences?

  14. Thanks you, only what i came for, no stupid talking THAT is a good tutorial 🙂

  15. Laxmi Dhakal Reply

    How to save sqlite data after we clear the data of that application in my application when I clear the data of the application from setting then the user has to register again the app is there any way to save data

  16. Mark Hannibal Reply

    Very well explained. Thank you for taking the time to make this video.

  17. DarkImaginaion Reply

    I followed the tutorial and got a warning that sharedPreferences may produce NullPointerException. When I run the app everything works but views are not updated. How can I resolve this?

  18. Aly Abdelaal Reply

    After all thanks you reserved
    i have question
    could i change the Shared preferences from an other Activity in The same App.
    like a "logout" after saving a check Box Value "Keep me login" to allow me return to Login Activity Again.

Write A Comment