2. 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”.
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.
5. 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.
6. 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.