是否有任何方法可以从扩展Roomdatabase 2的类(用@Database注释的类)中获取我的活动上下文? 我需要此上下文,以便可以在活动和此类之间初始化接口以传递一些操作?
代码:
@Database(entities = {Movie.class}, version = 1, exportSchema = false)
public abstract class MovieDatabase extends RoomDatabase {
private final static String TAG_LOG = MovieDatabase.class.getSimpleName();
public abstract IDatabaseAccessObject dao();
public MovieDatabase() {
super();
Log.w(TAG_LOG, "->MovieDatabase constructor is called.");
}
@Override
public void init(@NonNull DatabaseConfiguration configuration) {
super.init(configuration);
Log.w(TAG_LOG, "->init is called. This is called every time Room.databaseBuilder(,,) is accessed.");
}
@Override
public void close() {
super.close();
Log.w(TAG_LOG, "->close is called.");
}
@NonNull
@Override
public SupportSQLiteOpenHelper getOpenHelper() {
Log.w(TAG_LOG, "->getOpenHelper is called.");
return super.getOpenHelper();
}
@Override
public boolean isOpen() {
Log.w(TAG_LOG, "->isOpen is called.");
return super.isOpen();
}
@NonNull
@Override
protected SupportSQLiteOpenHelper createOpenHelper(DatabaseConfiguration config) {
Log.w(TAG_LOG, "->createOpenHelper is called.");
Log.d(TAG_LOG, "->createOpenHelper->config.name:" + config.name);
Log.d(TAG_LOG, "->createOpenHelper->config.callbacks:" + config.callbacks);
Log.d(TAG_LOG, "->createOpenHelper->config.requireMigration:" + config.requireMigration);
return null;
}
@NonNull
@Override
protected InvalidationTracker createInvalidationTracker() {
Log.w(TAG_LOG, "->createInvalidationTracker is called.");
return null;
}
@Override
public void clearAllTables() {
Log.w(TAG_LOG, "->clearAllTables is called.");
}
}