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));
}
});
you can use Sqlite
– Marcos Brinner