I want that the user stays logged in the app until he/she logs out. I got to know that we can use shared preferences for creating such sessions. But I have two types of users and it depends on the type, which activity will intent. How can I use shared preferences in such case? And also I am using intent.putExtras(), so how would the data be passed on to other activities if the app directly opens the mainactivity class.
public void loginHandler(View view){
userId = useridTIET.getText().toString();
password = passwordTIET.getText().toString();
if(userId.isEmpty()||password.isEmpty()){
Toast.makeText(this, "Empty fields!", Toast.LENGTH_SHORT).show();
}
else {
Log.i("User Type",userType);
if(userType.equals("resident")){
residentLogin();
}
else {
guardLogin();
}
}
}
public void residentLogin(){
if(condition){
Intent intent = new Intent(getApplicationContext(),NavigationActivity.class);
intent.putExtra("currentResident",currentResident);
startActivity(intent);
}
}
public void guardLogin(){
if(condition){
Intent intent = new Intent(getApplicationContext(),NavigationActivity2.class);
intent.putExtra("userId",userId);
startActivity(intent);
}
}
How should I proceed to create sessions? Thanks for your time:)
You can use like that
getSharedPreferences("guard",0)
getSharedPreferences("resident",0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.