# RoomDatabase.Callback

Artifact: [androidx.room:room-runtime](https://developer.android.com/jetpack/androidx/releases/room) [View Source](https://cs.android.com/search?q=file:androidx/room/RoomDatabase.+class:androidx.room.RoomDatabase.Callback) Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  abstract class RoomDatabase.Callback
  ```

*** ** * ** ***

Callback for `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase`

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Callback#Callback()()` | android |
| `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Callback#Callback()()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Callback#Callback()()` | N |

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Callback#onCreate(androidx.sqlite.SQLiteConnection)(connection: https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection)` Called when the database is created for the first time. | Cmn android N |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Callback#onCreate(androidx.sqlite.db.SupportSQLiteDatabase)(db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase)` Called when the database is created for the first time. | android |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Callback#onDestructiveMigration(androidx.sqlite.SQLiteConnection)(connection: https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection)` Called after the database was destructively migrated. | Cmn android N |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Callback#onDestructiveMigration(androidx.sqlite.db.SupportSQLiteDatabase)(db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase)` Called after the database was destructively migrated | android |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Callback#onOpen(androidx.sqlite.SQLiteConnection)(connection: https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection)` Called when the database has been opened. | Cmn android N |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)(db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase)` Called when the database has been opened. | android |

## Public constructors

### Callback

android Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
Callback()
```

### Callback

Cmn Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
Callback()
```

### Callback

N Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
Callback()
```

## Public functions

### onCreate

Cmn android N Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
open fun onCreate(connection: SQLiteConnection): Unit
```

Called when the database is created for the first time.

This function called after all the tables are created.

| Parameters |
|---|---|
| `connection: https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection` | The database connection. |

### onCreate

android Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
open fun onCreate(db: SupportSQLiteDatabase): Unit
```

Called when the database is created for the first time. This is called after all the tables are created.

This function is only called when Room is configured without a driver. If a driver is set using `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Builder#setDriver(androidx.sqlite.SQLiteDriver)`, then only the version that receives a `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection` is called.

| Parameters |
|---|---|
| `db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase` | The database. |

### onDestructiveMigration

Cmn android N Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
open fun onDestructiveMigration(connection: SQLiteConnection): Unit
```

Called after the database was destructively migrated.

| Parameters |
|---|---|
| `connection: https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection` | The database connection. |

### onDestructiveMigration

android Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/room#2.2.0)

```
open fun onDestructiveMigration(db: SupportSQLiteDatabase): Unit
```

Called after the database was destructively migrated

This function is only called when Room is configured without a driver. If a driver is set using `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Builder#setDriver(androidx.sqlite.SQLiteDriver)`, then only the version that receives a `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection` is called.

| Parameters |
|---|---|
| `db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase` | The database. |

### onOpen

Cmn android N Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
open fun onOpen(connection: SQLiteConnection): Unit
```

Called when the database has been opened.

| Parameters |
|---|---|
| `connection: https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection` | The database connection. |

### onOpen

android Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
open fun onOpen(db: SupportSQLiteDatabase): Unit
```

Called when the database has been opened.

This function is only called when Room is configured without a driver. If a driver is set using `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Builder#setDriver(androidx.sqlite.SQLiteDriver)`, then only the version that receives a `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection` is called.

| Parameters |
|---|---|
| `db: https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase` | The database. |