# 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)

*** ** * ** ***


```
public abstract class RoomDatabase.Callback
```

<br />

*** ** * ** ***

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

## Summary

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

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onCreate(androidx.sqlite.SQLiteConnection)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/SQLiteConnection connection)` Called when the database is created for the first time. |
| `void` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onCreate(androidx.sqlite.db.SupportSQLiteDatabase)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase db)` Called when the database is created for the first time. |
| `void` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onDestructiveMigration(androidx.sqlite.SQLiteConnection)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/SQLiteConnection connection)` Called after the database was destructively migrated. |
| `void` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onDestructiveMigration(androidx.sqlite.db.SupportSQLiteDatabase)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase db)` Called after the database was destructively migrated |
| `void` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onOpen(androidx.sqlite.SQLiteConnection)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/SQLiteConnection connection)` Called when the database has been opened. |
| `void` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteDatabase db)` Called when the database has been opened. |

## Public constructors

### Callback

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

```
public Callback()
```

### Callback

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

```
public Callback()
```

## Public methods

### onCreate

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

```
public void onCreate(@NonNull SQLiteConnection connection)
```

Called when the database is created for the first time.

This function called after all the tables are created.

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

### onCreate

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

```
public void onCreate(@NonNull SupportSQLiteDatabase db)
```

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/androidx/room/RoomDatabase.Builder#setDriver(androidx.sqlite.SQLiteDriver)`, then only the version that receives a `https://developer.android.com/reference/androidx/sqlite/SQLiteConnection` is called.

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

### onDestructiveMigration

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

```
public void onDestructiveMigration(@NonNull SQLiteConnection connection)
```

Called after the database was destructively migrated.

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

### onDestructiveMigration

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

```
public void onDestructiveMigration(@NonNull SupportSQLiteDatabase db)
```

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/androidx/room/RoomDatabase.Builder#setDriver(androidx.sqlite.SQLiteDriver)`, then only the version that receives a `https://developer.android.com/reference/androidx/sqlite/SQLiteConnection` is called.

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

### onOpen

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

```
public void onOpen(@NonNull SQLiteConnection connection)
```

Called when the database has been opened.

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

### onOpen

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

```
public void onOpen(@NonNull SupportSQLiteDatabase db)
```

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/androidx/room/RoomDatabase.Builder#setDriver(androidx.sqlite.SQLiteDriver)`, then only the version that receives a `https://developer.android.com/reference/androidx/sqlite/SQLiteConnection` is called.

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