0

I am new to android and trying to develop my first app. In my app, I have a listview activity that lists a group of stores. When the app users (anyone who downloaded the app) select their favorite store, +1 should be added to that store count. At a specific time during the year, I want to sort the array by store count and display the new favorite stores to the screen.

My question is, how can I store that data until it's time for me to evaluate the new standings?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Skip
  • 35
  • 9

3 Answers3

1

You could add store-count as key-value pairs to SharedPreferences

http://developer.android.com/guide/topics/data/data-storage.html#pref

It's a lightweight storage and pretty handy for stuff like this.

Anirudh
  • 2,524
  • 1
  • 14
  • 14
1

I would write the values to file using an ObjectOutputStream:

    public static void saveArray(String filename, String[] array) {
    try {
        FileOutputStream fos = openFileOutput(filename, Context.MODE_PRIVATE);
        ObjectOutputStream out = new ObjectOutputStream(fos);
        out.writeObject(array);
        out.flush();
        out.close();
    } catch (IOException e) {}
}

Then edit the above to save word counts as an int (or short) array.

lrAndroid
  • 2,834
  • 18
  • 27
0

Use SQLite database to store your Store name and its count value. With its use, you can enhance your app's storage possibilities up to full extent.

waqaslam
  • 67,549
  • 16
  • 165
  • 178