0

I am working with Android Studio 2.2.3 in order to watch data received from a bluetooth module in my smartphone's screen. I can see these values in my activity but as I am receiving values each 10 seconds (for example) I would like to save all this data in an array, database or anyplace. Once it was saved I would like to build a graphic using this saved data.

Here I have a picture of what I receive: enter image description here

So now I would like to save those values (53,54,55...) and I don't know how. Is there any way like making an ArrayList or some function to save it? I read about "SharedPreferences" but I think it is not designed for what I am looking for.

Thank you very much!

P.D: I hope I explained okay and sorry for my english.

  • You can just write it to disk as a text file. https://stackoverflow.com/questions/2885173/how-do-i-create-a-file-and-write-to-it-in-java – Endre Börcsök May 31 '17 at 15:07

1 Answers1

0

Shared Preferences could be, it allow to use Sets. You could convert your List into a HashSet or something similar and store it like that. When your read it back, convert it into an ArrayList.

//Retrieve the values
SharedPreferences prefs = getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE);
Set<String> set = prefs .getStringSet("key", null);
yourListOfStrings.addAll(set);


//Set the values
SharedPreferences prefs = getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE);
Set<String> set = new HashSet<String>();
set.addAll(yourListOfStrings);
prefs.putStringSet("key", set);
prefs.commit();

Regards,

Max Pinto
  • 1,463
  • 3
  • 16
  • 29