java - Can an ArrayList made using a constructor from a class be saved to SharedPreferences? -


so making simple wine list app. there 3 main activities.

  1. mainactivity - list of wines is, along fab takes addwineactivity. each list item on page shows thumbnail, wine name, price, , rating.

  2. addwineactivity - has couple of edittexts (to wine's name, price, , description), ratingbar (to wine rating), , button converts details strings , puts them into intent extras.

  3. winedetailsactivity - have nice page has of details wine in list clicked on.


i have app pretty working how want currently. thing need save list of wines wont reset after go in add wine, or if leave app , come back.

here tricky part (which doesn't since don't know saving device anyway yet). adding arraylist using class.

i have wine class has constructor looks this:

public wine(string mwinename, string mwineprice, string mwinerating, string mwinedescription, int mwineimageresourceid) {} 

so on mainactivity, add list looks this

wines.add(new wine(getintent().getstringextra("winename"), getintent().getstringextra("wineprice"), getintent().getstringextra("winerating"), getintent().getstringextra("winedescription"), r.drawable.mywinelogo)); 

what recommended way add list looks device? still shared preferences or not on right track?

if more details app wanted, ask them , i'll provide them.

thanks!

what recommended way add list looks device? still shared preferences or not on right track?

in end, have tabular data structure: rows (wines) , columns (name, rating, etc.).

when have tabular data structure, save table-friendly. sqlite database or form of file (e.g., json, xml).

sharedpreferences not well-suited this. convert table json , store string preference, that's relatively uncommon. imho, make sense if of rest of data more natural sharedpreferences (e.g., using preferencescreen collect them) , wanted keep together.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -