Skip to content

This class simplifies calls to SharedPreferences in a line of code. It can also do more like: saving a list of Strings, ints, and saving images. All in 1 line of code!

Notifications You must be signed in to change notification settings

InsanityOnABun/TinyDB--Android-Shared-Preferences-Turbo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 

Repository files navigation

TinyDB -- Android-Shared-Preferences-Turbo

This class simplifies calls to SharedPreferences in a line of code. It can also do more like: saving a list of strings, integers and saving images. All in 1 line of code!

Example usage:

TinyDB tinydb = new TinyDB(context);

//Put data in database
tinydb.putInt("clickCount", 2);
tinydb.putFloat("xPoint", 3.6f);
tinydb.putLong("userCount", 39832L);

tinydb.putString("userName", "john");
tinydb.putBoolean("isUserMale", true); 

tinydb.putList("MyUsers", mUsersArray);
tinydb.putImagePNG("DropBox/WorkImages", "MeAtlunch.png", lunchBitmap);

//Get data from database
int dataint = tinyDB.getInt("clickCount");
String datastring = tinyDB.getString("userName");
//These plus the corresponding get methods are all included

This is just an example of how easy it is to use. There are many more useful methods included in the class. Enjoy :)

If you'd like to also save Objects, use the methods:

tinydb.putObject(key, object);
tinydb.putListObject(key, objectsArray);

Example of saving Objects:

Person person = new Person("john", 24);
tinydb.putObject("user1", person); //saves the object
tinydb.getObject("user1", Person.class); // retrieves the object from storage

ArrayList<Person> usersWhoWon = new ArrayList<Person>();
tinydb.putListObject("allWinners", usersWhoWon);

Before you can use the save objects methods, you must first:

  1. Download Gson.jar

  2. Place the Gson.jar file into your projects "libs" folder (create one if you dont already have the folder)

  3. Uncomment the save objects methods in your copy of TinyDB.java, starting at: Line31, Line317, Line332, Line462, Line468

Installation: Just add the TinyDB.java file as a Java Class and you can now use it according to the examples shown above.

About

This class simplifies calls to SharedPreferences in a line of code. It can also do more like: saving a list of Strings, ints, and saving images. All in 1 line of code!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%