I have gone through this question and similar questions, but I am still unable to figure this out.
Earlier I was using SQLite
for my android app. Size of pre-populated Sqlite database is about 15 MB. I made an temporary android app to my copy my records into a new Realm database. The size of this new Realm database was about 150 MB. Then I opened it with Realm browser in Mac and compressed it. Size now reduced back to 15 MB.
But if I use encryption while creating new database and copying sqlite rows into it, size is approx 150 MB. When I opened it using Hex password, it opens fine. Then I compressed it as earlier -> size back to normal 15 MB. But, I don't know why, the encryption is removed now.
To counter this, I can only think of one solution. If I could apply encryption to already compressed Realm database. But, I couldn't figure out, how to do this in Android?
Edit - Some relevant parts -
Part 1 -
Realm.init(this);
byte[] key = new byte[64]; // Just for demonstration
RealmConfiguration config = new RealmConfiguration.Builder()
.name("QBank.realm")
.directory(getExternalFilesDir(null))
.encryptionKey(key)
.build();
Realm realm = Realm.getInstance(config);
Part 2 -
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button_sqlite2realm:
DatabaseAccess databaseAccess = DatabaseAccess.getInstance(this);
databaseAccess.open();
questionsList = databaseAccess.getAllQuestions();
databaseAccess.close();
Realm realm = Realm.getInstance(config);
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
for (QuestionBank question : questionsList){
realm.copyToRealmOrUpdate(question);
}
}
});
break;
}
}
For converting Encrypted database to Compressed database -> I pulled this realm database from android emulator -> opened it in Realm Browser (with Hex password) -> Compressed (but this newly created compressed database is now not encrypted)
P.S. - I know my question is descriptive, but I couldn't find a way to do this.