, , MainActivity, .
onCreate , , :
boolean isLoggedIn = checkUserStatus();
Intent intent = isLoggedIn ? new Intent(context, HomeActivity.class)
: new Intent(context, LoginActivity.class);
startActivity(intent);
checkUserStatus() - , , :
protected boolean checkUserStatus(){
boolean isLoggedIn ;
Context context = getApplicationContext();
SharedPreferences pref = context.getSharedPreferences("Session Data", MODE_PRIVATE);
isLoggedIn = pref.getBoolean("isLoggedIn", false);
return isLoggedIn ;
}
boolean true false:
SharedPreferences pref = context.getSharedPreferences(
"Session Data", MODE_PRIVATE);
SharedPreferences.Editor edit = pref.edit();
edit.putInt("LAST_VERSION_CODE", BuildConfig.VERSION_CODE);
edit.putBoolean("isLoggedIn", true);// or false if you log out
edit.commit();