humazed / RoomAsset

A helper library to help using Room with existing pre-populated database [DEPRECATED].
Apache License 2.0
135 stars 23 forks source link

Hi.I addCallback like this,but it's not call onCreate(), But onOpen() .it's have.Please tell me why.Thanks a lot #10

Closed HarryHaiVn closed 6 years ago

HarryHaiVn commented 6 years ago

return RoomAsset.databaseBuilder(appContext, AppDatabase.class, DATABASE_NAME) .addCallback(new Callback() { @Override public void onCreate(@NonNull SupportSQLiteDatabase db) { super.onCreate(db); Log.d("RoomAsset:------", "onCreate"); }

                @Override
                public void onOpen(@NonNull SupportSQLiteDatabase db) {
                    super.onOpen(db);
                    Log.d("RoomAsset:------", "onOpen");
                }
            })
            .build();
humazed commented 6 years ago

Because the creation of the database and the migration happens before onCreate has a chance to be called.

so after the method databaseBuilder is called the database is guaranteed to be created and you can perform your logic there.

I'm curious, why you need to know when the DB is created?