As SharedPrefereces help us to store persistent data I am using it in my application for storing small amount of data(using TinyDB) for which I don't feel the need of using SQLite.
What I'm doing is taking some value from user and storing it in an ArrayList. As the user exits the application or the OS kills the application and again the application is started I wish to add the new data in the same ArrayList mentioned above.
I don't understand how to search for it but tried and found this on SO itself.
Though it did not solve my problem so decided to ask.
EDIT : Code snippet
Adding elements to arraylist on button click
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
place = et.getText().toString();
if(place.length()!=0){
Toast.makeText(getBaseContext(), place + " is scanned.", Toast.LENGTH_SHORT).show();
placeArray.add(place);
CalculateLatLong();
}
else{
Toast.makeText(getBaseContext(),"Enter place to search.", Toast.LENGTH_SHORT).show();
}
}
});
In CalculateLatLong()
...
TinyDB tinydb = new TinyDB(this);
tinydb.putListString("locationName", placeArray);
...
I want to add placeArray
to locationName
As placeArray
is initialized to null on each kill of application so everytime its a new list which I want to merge with locationName
contents.
Do I need to do something by overriding the onPause state of activity? If yes then how?
Thankyou.