android-components / mozilla.components.browser.session / SessionManager

# SessionManager

`class SessionManager : Observable<Observer>` (source)

This class provides access to a centralized registry of all active sessions.

### Types

Observer | `interface Observer` Interface to be implemented by classes that want to observe the session manager.

### Constructors

<init> | `SessionManager(engine: Engine, defaultSession: () -> Session = null, delegate: Observable<Observer> = ObserverRegistry())` This class provides access to a centralized registry of all active sessions.

### Properties

all | `val all: List<Session>` Returns a list of all active sessions (including CustomTab sessions).
defaultSession | `val defaultSession: () -> Session`
engine | `val engine: Engine`
selectedSession | `val selectedSession: Session?` Gets the currently selected session if there is one.
selectedSessionOrThrow | `val selectedSessionOrThrow: Session` Gets the currently selected session or throws an IllegalStateException if no session is selected.
sessions | `val sessions: List<Session>` Returns a list of active sessions and filters out sessions used for CustomTabs.
size | `val size: Int` Returns the number of session including CustomTab sessions.

### Functions

add | `fun add(session: Session, selected: Boolean = false, engineSession: EngineSession? = null, parent: Session? = null): Unit` Adds the provided session.
createSnapshot | `fun createSnapshot(): SessionsSnapshot?` Produces a snapshot of this manager's state, suitable for restoring via SessionManager.restore. Only regular sessions are included in the snapshot. Private and Custom Tab sessions are omitted.
findSessionById | `fun findSessionById(id: String): Session?` Finds and returns the session with the given id. Returns null if no matching session could be found.
getEngineSession | `fun getEngineSession(session: Session = selectedSessionOrThrow): EngineSession?` Gets the linked engine session for the provided session (if it exists).
getOrCreateEngineSession | `fun getOrCreateEngineSession(session: Session = selectedSessionOrThrow): EngineSession` Gets the linked engine session for the provided session and creates it if needed.
onLowMemory | `fun onLowMemory(): Unit` Informs this SessionManager that the OS is in low memory condition so it can reduce its allocated objects.
remove | `fun remove(session: Session = selectedSessionOrThrow, selectParentIfExists: Boolean = false): Unit` Removes the provided session. If no session is provided then the selected session is removed.
removeAll | `fun removeAll(): Unit` Removes all sessions including CustomTab sessions.
removeSessions | `fun removeSessions(): Unit` Removes all sessions but CustomTab sessions.
restore | `fun restore(snapshot: SessionsSnapshot): Unit` Restores sessions from the provided SessionsSnapshot. Notification behaviour is as follows:
select | `fun select(session: Session): Unit` Marks the given session as selected.

### Companion Object Properties

NO_SELECTION | `const val NO_SELECTION: Int`