我是
的新手我正在制作移动网络捆绑包,并提供应用程序以显示我使用Room Insert Annotation创建数据库:
Insert
void insertBundle(BundleOfferModel bundleOfferModel);
然后,在app databases目录中创建数据库。然后我将其复制到我的PC并添加一些新数据,并将新修改的数据库文件复制到apk的assets文件夹。当我再次运行我的应用程序时,应用程序显示旧数据,但我想查看更新的数据库文件数据。我怎么能做到这一点?
数据库
@Database(entities = {BundleOfferModel.class}, version = 1, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
private static final String DATABASE_NAME = "bundles_offers.db";
private static AppDatabase INSTANCE;
public static AppDatabase getAppDatabase(Context context) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, DATABASE_NAME )
.openHelperFactory(new AssetSQLiteOpenHelperFactory())
.allowMainThreadQueries()
.build();
}
return INSTANCE;
}
public static void destroyInstance() {
INSTANCE = null;
}
public abstract BundleOfferDao bundleDao();
}
道
@Dao
public interface BundleOfferDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertBundle(BundleOfferModel bundleOfferModel);
@Query("SELECT * FROM bundles_offers")
List<BundleOfferModel> getAllBundlesOffers();
}