tborg

SessionManager.java

Apr 21st, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. package com.example.thomas.taken.helper;
  2.  
  3. import android.content.Context;
  4. import android.content.SharedPreferences;
  5. import android.content.SharedPreferences.Editor;
  6. import android.util.Log;
  7.  
  8. public class SessionManager {
  9.     // LogCat tag
  10.     private static String TAG = SessionManager.class.getSimpleName();
  11.  
  12.     // Shared Preferences
  13.     SharedPreferences pref;
  14.  
  15.     Editor editor;
  16.     Context _context;
  17.  
  18.     // Shared pref mode
  19.     int PRIVATE_MODE = 0;
  20.  
  21.     // Shared preferences file name
  22.     private static final String PREF_NAME = "TakenTracking";
  23.      
  24.     private static final String KEY_IS_LOGGEDIN = "isLoggedIn";
  25.  
  26.     public SessionManager(Context context) {
  27.         this._context = context;
  28.         pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
  29.         editor = pref.edit();
  30.     }
  31.  
  32.     public void setLogin(boolean isLoggedIn) {
  33.  
  34.         editor.putBoolean(KEY_IS_LOGGEDIN, isLoggedIn);
  35.  
  36.         // commit changes
  37.         editor.commit();
  38.  
  39.         Log.d(TAG, "User login session modified!");
  40.     }
  41.      
  42.     public boolean isLoggedIn(){
  43.         return pref.getBoolean(KEY_IS_LOGGEDIN, false);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment