Skip to content

Latest commit

 

History

History
63 lines (39 loc) · 2.15 KB

README.md

File metadata and controls

63 lines (39 loc) · 2.15 KB

sharedPreferencsGADS

Google Africa Android workshop on shared preference

SharedPreference

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)

handling shared preference

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

Initialize the shared preference on the context Activity

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.

Writing to shared preference:

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.

screenshot

sharedpref

Delete and clear from sharedPreference

call the method clear() to clear and .remove() to delete data. make sure to pass in the correct key.

Picasso Library

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);

Image Transfomation

  .load(url)
  .resize(50, 50)
  .centerCrop()
  .into(imageView)