List at Chapter 8 doesn't store the lists according to initial arrangement

I make the list in this order: x, Eat, Sleep , Wake Up, x. When I stop the app and start again, it is another way round, x, Wake up, Sleep, Eat, while the last x disappear. I sort of understand maybe, the x is regard as same, it is being deleted, however, I do not understand why the order has been reversed. Any advice?

Latest: it’s not necessarily reversed, the order just seem different.

Hi szekirk,

Thank you for reading through the book and your patience waiting for me to reply!

As you observed, saving a value into SharedPreferences using a key already in use will overwrite the previous value. This is why one list titled x is returned when the app is started again, despite creating two.

The order of the lists is defined by SharedPreferences and the Android SDK. Unfortunately there’s little control over the ordering of the objects returned by SharedPreferences.

This highlights one of the limitations of using SharedPreferences in this way. It’s a brilliant way for saving quick values but it’s no replacement for a database solution we introduce later on in the book.

I hope that explains what is going on here. If you have any further questions please reach out to me and I’ll be happy to help.