The essence of the question is about serializing and persisting objects, then later deserializing them. There are many ways to do this, and the more robust and complex solutions often involve a database, typically SQLite on Android, and some Object Relational Mapping framework.
However, such a robust solution may be overkill in this case, since the use case is for serializing and saving a very small list of objects, each of which have a limited number of fields. The most common way to save small chunks of data on Android is in Shared Preferences. You can get a reference to the object that manages these with:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
Once you have this, you save Strings to persistent storage with code like this:
SharedPreferences.Editor editor = preferences.edit();
editor.putString("savedBeacons", savedBeaconsAsString);
editor.apply();
Then load them back like this:
String savedBeaconsAsString = preferences.getString("savedBeacons", null);
Of course, the above is only saving a single String to persistent storage. How do you convert a list of objects to String, and how do you convert a String to a list of objects. This is called serialization.
There are lots of ways to do this including converting to and from JSON. One of the simplest methods is using Java Serialization APIs. The main disadvantage of these is that they can fail to deserialize (load back) your object if you later change the definition of the object in Java code after records has been saved.
Here is an example of converting an array of savedBeacons to and from a String, taken from this related answer. Note that the code below assumes that savedBeacons is an array, not an ArrayList
as your code shows. I have shown this as an array for simplicity because ArrayList
is not serializable.
// serialize
ByteArrayOutputStream out = new ByteArrayOutputStream();
new ObjectOutputStream(out).writeObject(savedBeacons);
String savedBeaconsAsString = new String(Hex.encodeHex(out.toByteArray()));
// deserialize
ByteArrayInputStream in = new ByteArrayInputStream(Hex.decodeHex(savedBeaconsAsString.toCharArray()));
savedBeacons = (BeaconDevice[]) new ObjectInputStream(in).readObject()));