thejaswi thejaswi - 3 years ago 169
Android Question

Saving facebook login details locally in android app

I am developing an Android app where the user has the facility of Facebook sharing. I have the login details of the user for the Facebook, now what I am trying to do is these login details should be saved until the application is not deleted.

When I tried to find the answer for this, I got some answers stating about shared preferences. But I am not cleared exactly how it works.

Here is what I am trying to do,

Username = username.getText().toString();

PassWord = password.getText().toString();

where username and password are 2 edittext fields. When the user enters for the first time into Facebook, I should save these data somewhere for my future reference so that he need not login again.

Can any one let me know how to achieve this?

Answer Source
// Save your info
SharedPreferences settings = getSharedPreferences("my_file_name", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("username", username.getText().toString());
editor.putString("password", password.getText().toString());

// Obtain your info
SharedPreferences settings = getSharedPreferences("my_file_name", 0);
String username = settings.getString("username", "");
String password = settings.getString("password", "");

A file will be created in:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download