In this video we learn, how we can save a List of custom Objects to Shared Preferences using Google’s GSON Library. For this purpose we will turn the ArrayList …




  1. Coding in Flow Reply

    * * *
    I added a link to the example code into the description box!
    * * *

  2. Marin Gela Reply

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.project/com.example.project.MainActivity}: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

  3. Frederik Munch-Hansen Reply

    Hi there. What to do – if my array of objects is a string array? Changing the arrayList to arrayString won't work :-(?

  4. hi so i did what you said on the video but when i click on the save button the app crashes, in the logcat it says

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.reminded/com.example.reminded.SecondActivity}: java.lang.IllegalArgumentException: class android.widget.Button declares multiple JSON fields named mMinWidth

  5. Exactly what I was looking for. What a simple and elegant solution. Cheers!

  6. If I press back button on an activity is onDestroy() called? if so i when its called i can use this to save data when my activity gets destroyed

  7. Henrik Poulsen Reply

    Thank you very much for this excellent tutorial. Very simple, very effective 🙂

  8. Dhaval Solanki Reply

    Thank you so much, this is exactly what I am looking for my app.

  9. D. Refaeli Reply

    I'm not sure Shared Preferences should be used to store big amounts of data, but rather flags and the like. So if your data is too big, use a DB.

  10. du bist wirklich toll!
    du schaffst das immer die Idee in so einer kurzen Zeti sehr deutlich zu erklären!
    Ich danke dir vielmals!

    nun habe ich eine kleiene Frage bitte: wie kann ich die Daten automatisch speichern (wenn die App gescloßen oder gekillt wird)?


  11. Nguyen Nguyen Reply

    I made my small app for my study at uni, with very few instructions, and your tutorial helped me a lot. THANKS <3<3<3

  12. Anatole Couasnon Reply

    Thanks for this tutorial ! is someone know how to do the same thing out of an activity ? I have severals activity and i want to save datas from each one, so a class to save the datas would be easier than to do the same methods each time … Thanks for the time you will take to answer me

  13. Thks alot .
    I also saw this in some blog, and i tried to use this example with favorite (button) for each item , save correct but in scrolling recyclerview there are som errors. If u have a video implementing this please link

  14. cibo technologies Reply

    Thanks buddy, You did a great job. So saved my another day. Thanks

  15. Robert Nino Reply

    Hello sir can you make a tutorial about arrays with activity in it. Exmple.
    Arr[0] = activity1.class
    And pass it to next activity

  16. Siddharth Shakya Reply

    can you make a tutorial explaining recyclerview with AsyncTask with custom adapter

  17. Luis Alfredo Caballero Reply

    Tomatoes hahaha hello again, and thanks for the help.

  18. Antti Kuisma Reply

    Hey, can you help me? loadData() crash my app… I tried to make it like when I add an item to the list, it also saves it at the same time.

  19. Mücahit Alper Kaşlı Reply

    Thank you so much for clear explanation!
    I'm trying to figure out something,I hope you can help.
    Task:Get data of only all mLine2 strings which we saved.And send all data through bluetooth adaptor.Bluetooth app ready,saving all objects with your way also ready,now I just need to send mLine2 abjects one by one through bluetooth.
    Hope you can help 🙂

  20. Oomptz Fantasy & Ambient Theme Music Reply

    I am confused. How can it resolve variable mExampleList if you are not creating it in the beginning?

  21. Pricop George Reply

    For me the load function isnt working gson.fromJson(json ,type) allways returns null

Write A Comment