Here's some code that stores a user token and a password in
SharedPreferences:
                private String PREFS="preferences";
                private String TOKEN_STRING="token";
                private String PASSWORD_STRING="password";
// retrieving the token and password
                SharedPreferences settings = this.getSharedPreferences(PREFS, 
0);
                if (settings.contains(TOKEN_STRING) && settings.containts
(PASSWORD_STRING)) {
                        String secret = settings.getString(PASSWORD_STRING, "");
                        String token = settings.getString(TOKEN_STRING, "");
                        if(!(token.equals("") || secret.equals(""))) {
                                // token is good
                                // password is good
                        }
                }

// removing the token and password
            SharedPreferences settings = this.getSharedPreferences(PREFS,
0);
            SharedPreferences.Editor editor = settings.edit();
            editor.remove(TOKEN_STRING);
            editor.remove(SECRET_STRING);
            editor.commit();

// setting the token and password
            SharedPreferences settings = this.getSharedPreferences(PREFS,
0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(TOKEN_STRING, "user token");
            editor.putString(SECRET_STRING, "user password);
            editor.commit();


On Jan 19, 2:47 am, pranav09 <[email protected]> wrote:
> Hi all,
>
> I am developing an application which requires to store email id and
> password, so that the user can directly redirect to his home page if
> the user is already exists. A few day ago i read that
> SharedPreferences is used for storing and retrieving the data.
>
> How can i use SharedPreferences concept to store and retrieve data.
> Anybody have any idea to do this way? If it is possible by
> understanding me through the code because i read that things but i can
> not get it properly.
>
> Thanks.
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to