gpt4 book ai didi

java - ActiveAndroid 使用现有数据库

转载 作者:行者123 更新时间:2023-11-30 10:51:52 26 4
gpt4 key购买 nike

我正在使用 ActiveAndroid作为第三方库,以便在 android 中使用 sqlite 数据库,我在使用该库创建和使用新数据库时没有任何问题,但我不知道如何将我自己的现有数据库与该库一起使用?我想将我自己的数据库放入 Assets 文件夹并将其加载到 ActiveAndroid图书馆。

public class Application extends com.activeandroid.app.Application
{

@Override
public void onCreate()
{
super.onCreate();
createDatabase();
}

private void createDatabase()
{
Configuration dbConfiguration = new Configuration.Builder(this).setDatabaseName("dastan.db").create();
ActiveAndroid.initialize(dbConfiguration);

}


@Override
public void onLowMemory()
{
android.os.Process.killProcess(android.os.Process.myPid());
super.onLowMemory();
}
}

最佳答案

“xArthasx”在 Issue 41 中说:

If you have the file (sqlite database) and the tables keep the same structure as the class you made in java, you should be able use the database by coping the file (sqlite database) to the assets directory (project directory) and set the AA_DB_NAME equals to the name of the file.

如果现有数据库不是使用 ActiveAndroid 创建的,您可能需要迁移数据;见Use ActiveAndroid on existing database-content .

关于java - ActiveAndroid 使用现有数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34574956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com