Posts

Showing posts with the label Shared Preference

Shared Preference or Session Management (Login-Logout)

Image
Android provides many ways to store data in application. One of those ways is to use of Shared Preference . Shared Preference allows you to save and retrieve data in the form of key-value pair. For getting shared preference data of your app, you have to call a method getSharedPreference() , that will return SharedPreference instance that contains key-value pairs of preference. SharedPreferences preferences = getSharedPreferences("login", Context.MODE_PRIVATE); Remember this name "login" remains same for fetching all data related to login task and also its key: Suppose, we put "isUserLogin" boolean true after login success, then first time app launch, in Launcher Screen we have to check same key "isUserLogin". if (preferences.contains("isUserLogin")) { Intent intent = new Intent(SplashActivity.this, HomeActivity.class); startActivity(intent); } else { Intent intent = new Intent(SplashActivity.this, LoginActivity.class); ...