Android Share 
Preferences 
By: Ajay Panchal
Introduction 
▪ This is a sample android application development tutorial that show 
a how to save a android from data when ever immediately close the 
application in between registration. It is a so much treble full to refill 
all form data again. 
▪ So this tutorial show how you can put functionality in your android 
application, your application do not face this kind of problem while 
register in your android application. 
▪ It is an easy task to shave a form data while application is 
immediately close. We can call this functionality “Shared 
Preference”.
Shared Preference 
▪ The shared preference is a class that provide a storage area to store a 
small amount of temporary data you can save. 
▪ New Application with One Edit Text Control to take a user data into 
the form. 
▪ And we Are going to preserve value of this edit text control. Here we 
are user a predefined Class Called Shared Preference That Provided in 
to the android library.
New Application with one EditText 
Control
Code to set A text while restart A app 
▪ This code is written in on create method of class. 
▪ Code in onCreate() 
private EditText et; 
setContentView(R.layout.activity_main); 
et=(EditText) findViewById(R.id.editText1); 
SharedPreferences settings=getSharedPreferences("MYPREFS", 0); 
et.setText(settings.getString("tvalue", "")); 
▪ You can write private EditText et; in Global section of class if error.
Code For Application close 
▪ This code Preserve the current data that fill in the control. 
▪ The class shared preference class contain function for storing a 
intellectual data. 
▪ SharedPreference.Editor 
– android.content.SharedPreferences.Editor; 
– putString() is a method that provide a functionality to store data into the 
storage area, in this case SharedPreferences.
code 
▪ @Override 
▪ protected void onStop() { 
▪ // TODO Auto-generated method stub 
▪ super.onStop(); 
▪ SharedPreferences settings = getSharedPreferences("MYPREFS", 0); 
▪ SharedPreferences.Editor editor=settings.edit(); 
▪ editor.putString("tvalue", et.getText().toString()); 
▪ editor.commit(); 
▪ }
Thank You!

Android share preferences

  • 1.
    Android Share Preferences By: Ajay Panchal
  • 2.
    Introduction ▪ Thisis a sample android application development tutorial that show a how to save a android from data when ever immediately close the application in between registration. It is a so much treble full to refill all form data again. ▪ So this tutorial show how you can put functionality in your android application, your application do not face this kind of problem while register in your android application. ▪ It is an easy task to shave a form data while application is immediately close. We can call this functionality “Shared Preference”.
  • 3.
    Shared Preference ▪The shared preference is a class that provide a storage area to store a small amount of temporary data you can save. ▪ New Application with One Edit Text Control to take a user data into the form. ▪ And we Are going to preserve value of this edit text control. Here we are user a predefined Class Called Shared Preference That Provided in to the android library.
  • 4.
    New Application withone EditText Control
  • 5.
    Code to setA text while restart A app ▪ This code is written in on create method of class. ▪ Code in onCreate() private EditText et; setContentView(R.layout.activity_main); et=(EditText) findViewById(R.id.editText1); SharedPreferences settings=getSharedPreferences("MYPREFS", 0); et.setText(settings.getString("tvalue", "")); ▪ You can write private EditText et; in Global section of class if error.
  • 6.
    Code For Applicationclose ▪ This code Preserve the current data that fill in the control. ▪ The class shared preference class contain function for storing a intellectual data. ▪ SharedPreference.Editor – android.content.SharedPreferences.Editor; – putString() is a method that provide a functionality to store data into the storage area, in this case SharedPreferences.
  • 7.
    code ▪ @Override ▪ protected void onStop() { ▪ // TODO Auto-generated method stub ▪ super.onStop(); ▪ SharedPreferences settings = getSharedPreferences("MYPREFS", 0); ▪ SharedPreferences.Editor editor=settings.edit(); ▪ editor.putString("tvalue", et.getText().toString()); ▪ editor.commit(); ▪ }
  • 8.