HOW TO USE SHARED PREFERENCES AND MANAGE USER SESSIONS
In Android Storage can be done in many ways and one of the way is shared preferences.Shared Preferences allows us to manage session.Since Session are useful when you want to store user data globally through out the application. This can be done in two ways. One is storing them in a global variables and second is storing the data in shared preferences.
When to use Shared Preferences ?
1.You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).
2. when you want to have an login page where there is an option to save the user name and password details.
3.Think of a situation where you wanna save a small value (a flag probably) that you wanna refer later sometime when user launches the application. Then shared preference comes into action.
You may ask, why we can do it using sqlite too right? But the problem of
You may ask, why we can do it using sqlite too right? But the problem of
sqlite is that it’ll want you to write lengthy codes and supporting classes. Shared Preference let you read and write values in couple of lines easily. But always remember, shared preference is not a solution for you to keep complex relational data.
Final Result looks like this


No comments:
Post a Comment