Google Africa Android workshop on shared preference
This is on of the most awesome Data Storage Android provides. It provides a way in which one can store and retrieve small amount of data in the form of key-values pairs. (primitive data types: integer, float, boolean, string, long)
In the case of single files we use getPreference to get the values For the case of Multiple files we use getSharedPreference and pass the file name as the parameter
In our activity make sure to initialize the shared preference
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
For the case of multiple shared preference:
SharedPreferences sharedPref = getSharedPreferences("FileName",Context.MODE_PRIVATE);
.MODE_Private makes sure we only access the files within our application. FileName is the file to be accessed only.
We will need an editor to save and retrieve changes made to shared preference
mEditor.putString(Name, name);
mEditor.putString(Phone,pass);
mEditor.putString(Email,email);
mEditor.commit();
From the code above,We created the sharedPreference.Editor by calling the .editor method. The added up all the strings using PutString and save all teh changes we use commit method.
call the method clear() to clear and .remove() to delete data. make sure to pass in the correct key.
a powerful library that allows you to load you images into your app with 1 if no 2 lines of code.
Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView);
.load(url)
.resize(50, 50)
.centerCrop()
.into(imageView)