Android 如何使用各种领域数据库?
我需要使用4个领域数据库,以便在每个领域中保存4个不同的对象,我在编程和领域以及我的学习方面是新手,但我在领域文档中发现了这一点:Android 如何使用各种领域数据库?,android,database,realm,Android,Database,Realm,我需要使用4个领域数据库,以便在每个领域中保存4个不同的对象,我在编程和领域以及我的学习方面是新手,但我在领域文档中发现了这一点: RealmConfiguration myConfig=newrealmconfiguration.Builder() .name(“myrealm.realm”) .阴谋厌恶(2) .modules(新的MyCustomSchema()) .build() RealmConfiguration otherConfig=newrealmconfiguration.B
RealmConfiguration myConfig=newrealmconfiguration.Builder()
.name(“myrealm.realm”)
.阴谋厌恶(2)
.modules(新的MyCustomSchema())
.build()代码>
RealmConfiguration otherConfig=newrealmconfiguration.Builder()
.name(“otherrealm.realm”)
.阴谋厌恶(5)
.modules(新的MyOtherSchema())
.build()代码>
realmmyrealm=Realm.getInstance(myConfig);
Realm-otherRealm=Realm.getInstance(otherConfig)代码>
我认为这段代码应该放在MyApplication类中,但是我不能设置一个DefaultInstance
,所以在我的MainActivity中,我不能获取默认实例并像往常一样使用它,我需要获取具有我想要的配置的实例。
这是我第一次来这里,对我的错误和糟糕的英语很抱歉。谢谢大家。您确定需要不同的数据库吗?您可能只需要一个数据库和不同的对象表。需要使用我想要的配置来获取实例。
是的,这就是为什么这可能是解决方案,但我不知道该怎么做@ariochdivij666@EpicPandaForce但我需要在代码中看到它,并知道使用它的位置