How to update initial data in realm after update of apk?
You have to implement RealmMigration and pass it to RealmConfiguration.Builder().migration()
.
Something like this:
public class RealmMigrationAgent implements RealmMigration
{
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
RealmSchema schema = realm.getSchema();
if (oldVersion == 0) {
schema.get("InventDisableObject").addField("Reason", int.class);
oldVersion++;
}
if (oldVersion == 1) {
if (!schema.get("ActionObject").hasField("Annual"))
schema.get("ActionObject").addField("Annual", boolean.class);
oldVersion++;
}
if (oldVersion == 2) {
if (!schema.get("ActionObject").hasField("Hash"))
schema.get("ActionObject").addField("Hash", String.class);
if (!schema.get("ActionObject").hasField("Manual"))
schema.get("ActionObject").addField("Manual", boolean.class);
oldVersion++;
}
if (oldVersion == 3) {
if (!schema.get("OutletObject").hasField("Code"))
schema.get("OutletObject").addField("Code", String.class);
oldVersion++;
}
}
}
Incrementally adding scheme updates for every new scheme version.
I can see you have some class Migration
for migration reason - can you provide the code of it?
Detect change in realm database and update remote database android
As mentioned in Realm Documentation
-Add change listener.
-Add data
-The change is instantly reflected in onChangeListener.
private RealmResults<Dog> puppies;
// ...
puppies = realm.where(Dog.class).lessThan("age", 2).findAll();
puppies.size(); // => 0
realm.executeTransaction(new Realm.Transaction() {
@Override
void public execute(Realm realm) {
Dog dog = realm.createObject(Dog.class);
dog.setName("Fido");
dog.setAge(1);
}
});
puppies.addChangeListener(new RealmChangeListener() {
@Override
public void onChange(RealmResults<Dog> results) {
// results and puppies point are both up to date
results.size(); // => 1
puppies.size(); // => 1
}
});
UPDATE
localRealm.addChangeListener(new RealmChangeListener<Realm>() {
@Override
public void onChange(Realm realm) {
//do stuff
}
});
Related Topics
Horizontalscrollview Inside Swiperefreshlayout
Androidruntime: Fatal Exception: Androidmapsapi-Zoomtablemanager
Disable Sound from Notificationchannel
How to Remove All Listeners Added with Addtextchangedlistener
How to Create Android Spinner Without Down Triangle on the Right Side of the Widget
Horizontal Scrolling Grid View
Return Value from Asynctask Class Onpostexecute Method
Sqlite Returned an Error Code of 14
How to Start Power Manager of All Android Manufactures to Enable Background and Push Notification
How to Get Current Date in Android
Android Listview with Checkbox and All Clickable
How to Set the Initial Zoom/Width for a Webview
Does the Android Art Runtime Have the Same Method Limit Limitations as Dalvik
Dagger 2.10 Android Subcomponents and Builders