My application is simply a managing database application. I have a remote mysql server set up and my android studio application uses http post request to connect to that server.
you could it done in many ways like store data in sharedpreference or database or simply create a class that contains static variables.
To store and get data from shared preference use this.
public class MyPreference {
SharedPreferences myPrefs;
SharedPreferences.Editor prefEditor;
Context context;
// ------------------------------------------------------------------costructor
public MyPreference(Context context) {
this.context = context;
myPrefs = context.getSharedPreferences("myPrefs", 0);
}
// ----------------------------------------------------------------------- user login
public void setLogin() {
prefEditor = myPrefs.edit();
prefEditor.putBoolean("login", true);
prefEditor.commit();
}
public boolean isLogin() {
return myPrefs.getBoolean("login", false);
}
public void setPassword(String userPass) {
prefEditor = myPrefs.edit();
prefEditor.putString("user", userPass);
prefEditor.commit();
}
public String getPassword() {
return myPrefs.getString("user", "");
}
}