You can Use SharedPreferences.
Take a Boolean Value and set it to true when you login.
And after you click on Logout set it to False. Redirect the pages after your splash screen accordingly.
You can create a sperate class of sharedPreferences.
Eg :
public class CustomSharedPreferences {
public CustomSharedPreferences(Context context) {
// TODO Auto-generated constructor stub
prefs = getMyPreferences(context);
this._context = context;
prefs = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = prefs.edit();
}
private static SharedPreferences getMyPreferences(Context context) {
return context.getSharedPreferences(Util.APP_PREFERENCES,
Context.MODE_PRIVATE);
}
public boolean isLogin() {
return prefs.getBoolean("isLogin", false);
}
public void setIsLogin(boolean isLogin) {
this.isLogin = isLogin;
editor.putBoolean("isLogin", isLogin).commit();
}
}
//SplashScreenActivity
public class SplashScreenActivity extends AppCompatActivity {
private CustomSharedPreferences customSharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
customSharedPreferences = new CustomSharedPreferences(getApplicationContext());
new Handler().postDelayed(new Runnable() {
// Using handler with postDelayed called runnable run method
@Override
public void run() {
Intent i;
if (customSharedPreferences.isLogin()) {
i = new Intent(SplashScreenActivity.this, MainActivity.class);
} else {
i = new Intent(SplashScreenActivity.this, LoginActivity.class);
}
startActivity(i);
finish();
}
}, 5 * 1000); // wait for 5 seconds
}
}
//LoginActivity
public class LoginActivity{
//Object of CustomSharedPreferences Class
customSharedPreferences = new CustomSharedPreferences(getApplicationContext());
//After Clicking the Login Button
customSharedPreferences.setIsLogin(true);
}
4
solved How Do i implement Login and Logout Functionality in my android app? [closed]