setBackgroundDbConnection static method

void setBackgroundDbConnection(
  1. SqliteConnection db
)

Sets the SqliteConnection to be used by the background isolate.

This must be called by the user-provided AppInitializationCallback after a database connection has been established for the background isolate.

// In your AppInitializationCallback:
@pragma('vm:entry-point')
Future<void> _myAppBackgroundInit(ServiceInstance service) async {
  final backgroundDb = await AppDatabase().openNewConnection(); // Open DB for this isolate
  GenericBackgroundService.setBackgroundDbConnection(backgroundDb);
  // ... rest of initialization ...
}

Implementation

static void setBackgroundDbConnection(SqliteConnection db) {
  BackgroundService._backgroundDbConnection = db;
  log("BackgroundService: Background DB connection has been set.");
}