Android storage

Asked

Viewed 51 times

0

I am starting in the universe of Android, and I have the following question:

In a login system, which type of storage should I use to persist the data of the user who logged in to that session, and when I click exit "kill" this session information?

2 answers

0

A good option is to use some web service to log in and store your data and use sqlLite as if it were a "super cache". Take a look at firebase, it has great ways to authenticate: by email or social network. Also you can save your data and files. https://firebase.google.com/? hl=en

0

There are some forms of persistence on Android. You can use either ready-to-authenticate Apis (like Facebook and Google), or simple databases like Android’s own Sqlite or even Sharedpreferences.

An example would be, you authenticate and save the data in Sharedprefences and when the user quit you clear the preferences.

In this example below I persisted the login data in the preferences (that stays in the app) and when the user opens the app again I check if he has already logged in once in his life and if he did, he need not perform again.

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    binding = DataBindingUtil.setContentView(this, R.layout.activity_login);

    preferences = getSharedPreferences(Contract.SETTINGS_PREF, 0);
    String name = preferences.getString(Contract.USER_NAME_PREF, "");
    String email = preferences.getString(Contract.USER_EMAIL_PREF, "");
    String password = preferences.getString(Contract.USER_PASSWORD_PREF, "");

    if (!email.isEmpty() && !password.isEmpty()) {
        logIn(email, password);
    }

    binding.txtCreateAccount.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(LoginActivity.this, CreateAccountActivity.class));
        }
    });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.