0

Hello I am building one application in my application everything works fine now I want to add session in my application,when user run application first time user should log in but after closing and again when user open my app,my app should not ask for log in again..

3 Answers3

1

Creating a "session" in Android is very complex, if you want complete functionality.

You sound like you only need to do this once - in which case you should probably use SharedPreferences

How to use SharedPreferences in Android to store, fetch and edit values

This is an easy way to handle simple data storage. In your launch activity you can check it to see if the user is "logged" in (in onCreate or onResume) - if not, launch a login activity.

If you need this as a true "login" then you need to do that in every activity. Also, you probably need to update user activity to keep them "logged in" - in which case search "automatic logout" - it depends on your particular needs and app. It can get very complex.

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36
0

You can use a simple SQLite, with User (for example) table. If the user login, INSERT the table. If logout, DELETE the table.

Then you just need to check whether the table is empty (not logged in) or not (logged in), using COUNT query.

Blaze Tama
  • 10,828
  • 13
  • 69
  • 129
0

there is nothing called "Session" in android, after successful login you have to save accesstoken or some other variable with you will get after succesful login in device only. you can use:

1) SharedPrefrences
2). Sqlite Database

everytime you have to check the values in sharedpref, where you want user to be logded in. if values are there in database or prefrences, user can continue enjoy with app else popup your login screen.

if you want something like website means if user haven't touch screen or open some other app then session will be expire, then you need you implement clear prefrence and database in onpause or on stop also.

Pankaj Arora
  • 10,224
  • 2
  • 37
  • 59
  • i know there is no session in android so i follow this links but i am using dynamic data http://www.tutorialspoint.com/android/android_session_management.htm –  Nov 19 '14 at 10:43
  • using json response from my php –  Nov 19 '14 at 10:46
  • obviously it will be dynamic mate, after getting response from server you have to save data in shared pref, you need a workaround? – Pankaj Arora Nov 19 '14 at 10:48
  • so tell me where should i do process of shared prefrenc and how? –  Nov 19 '14 at 12:06