Overview
TheSessionManager class handles user session persistence across app launches. It stores user credentials and role information in Android’s SharedPreferences, enabling automatic login and role-based navigation.
This class is used throughout the app to maintain user authentication state and determine role-based access control.
Class Definition
SessionManager.java
Constructor
Initializes the session manager with application context and sets up SharedPreferences.Parameters:
context(Context) - Application context for accessing SharedPreferences
Methods
createLoginSession
The unique identifier for the user (typically email or Firebase UID)
The user’s role - either “Manager” or “Salesperson”
MainActivity.java
getUserDetails
"id"- User identifier (or “Not Found” if no session exists)"role"- User role (or “Not Found” if no session exists)
The stored user identifier from the active session
The stored user role (“Manager” or “Salesperson”)
logoutUser
AccountManager.java
Constants
The name of the SharedPreferences file where session data is stored
Key for storing/retrieving the user identifier
Public constant key for storing/retrieving the user role
SharedPreferences access mode (private to this app)
Integration Points
TheSessionManager is used in several key activities:
- MainActivity - Checks for existing session on app launch
- ManagerMain - Retrieves manager ID for data queries
- SalespersonMain - Retrieves salesperson ID for personalization
- MyTeam - Gets manager ID to filter team members
- AccountManager - Provides logout functionality
Source Reference
File:~/workspace/source/app/src/main/java/project/avishkar/salesmanagement/SessionManager.java
Related Classes
View AccountManager documentation for logout implementation