# PackageInstaller.SessionCallback

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# SessionCallback

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/content/pm/PackageInstaller.SessionCallback "View this page in Java")  

```
abstract class SessionCallback
```

|---|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                             ||
| ↳ | [android.content.pm.PackageInstaller.SessionCallback](https://developer.android.com/reference/kotlin/android/content/pm/PackageInstaller.SessionCallback#) |

Events for observing session lifecycle.

A typical session lifecycle looks like this:

- An installer creates a session to indicate pending app delivery. All install details are available at this point.
- The installer opens the session to deliver APK data. Note that a session may be opened and closed multiple times as network connectivity changes. The installer may deliver periodic progress updates.
- The installer commits or abandons the session, resulting in the session being finished.

## Summary

|                                                                  Public constructors                                                                  ||
|----------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [SessionCallback](https://developer.android.com/reference/kotlin/android/content/pm/PackageInstaller.SessionCallback#SessionCallback())`()` <br /> |

|                                                                                                                                                                                                                                                 Public methods                                                                                                                                                                                                                                                 ||
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onActiveChanged](https://developer.android.com/reference/kotlin/android/content/pm/PackageInstaller.SessionCallback#onActiveChanged(kotlin.Int,%20kotlin.Boolean))`(`sessionId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `active:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Active state for session has been changed.              |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onBadgingChanged](https://developer.android.com/reference/kotlin/android/content/pm/PackageInstaller.SessionCallback#onBadgingChanged(kotlin.Int))`(`sessionId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Badging details for an existing session has changed.                                                                                                                    |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onCreated](https://developer.android.com/reference/kotlin/android/content/pm/PackageInstaller.SessionCallback#onCreated(kotlin.Int))`(`sessionId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` New session has been created.                                                                                                                                                         |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onFinished](https://developer.android.com/reference/kotlin/android/content/pm/PackageInstaller.SessionCallback#onFinished(kotlin.Int,%20kotlin.Boolean))`(`sessionId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `success:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Session has completely finished, either with success or failure. |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onProgressChanged](https://developer.android.com/reference/kotlin/android/content/pm/PackageInstaller.SessionCallback#onProgressChanged(kotlin.Int,%20kotlin.Float))`(`sessionId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `progress:` `[Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html)`)` Progress for given session has been updated.            |

## Public constructors

### SessionCallback

```
SessionCallback()
```

## Public methods

### onActiveChanged

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun onActiveChanged(
    sessionId: Int, 
    active: Boolean
): Unit
```

Active state for session has been changed.

A session is considered active whenever there is ongoing forward progress being made, such as the installer holding an open[Session](https://developer.android.com/reference/kotlin/android/content/pm/PackageInstaller.Session)instance while streaming data into place, or the system optimizing code as the result of[Session.commit(IntentSender)](https://developer.android.com/reference/kotlin/android/content/pm/PackageInstaller.Session#commit(android.content.IntentSender)).

If the installer closes the[Session](https://developer.android.com/reference/kotlin/android/content/pm/PackageInstaller.Session)without committing, the session is considered inactive until the installer opens the session again.  

### onBadgingChanged

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun onBadgingChanged(sessionId: Int): Unit
```

Badging details for an existing session has changed. For example, the app icon or label has been updated.  

### onCreated

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun onCreated(sessionId: Int): Unit
```

New session has been created. Details about the session can be obtained from[PackageInstaller.getSessionInfo(int)](https://developer.android.com/reference/kotlin/android/content/pm/PackageInstaller#getSessionInfo(kotlin.Int)).  

### onFinished

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun onFinished(
    sessionId: Int, 
    success: Boolean
): Unit
```

Session has completely finished, either with success or failure.  

### onProgressChanged

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
abstract fun onProgressChanged(
    sessionId: Int, 
    progress: Float
): Unit
```

Progress for given session has been updated.

Note that this progress may not directly correspond to the value reported by[PackageInstaller.Session.setStagingProgress(float)](https://developer.android.com/reference/kotlin/android/content/pm/PackageInstaller.Session#setStagingProgress(kotlin.Float)), as the system may carve out a portion of the overall progress to represent its own internal installation work.