Data objects is not been saved permanently into the realm db


#1

Hi All,

I am new to Realm and find it to be excellent. i set up realm 5.8.0 in the gradle and everything went fine. the problem im having is that the data objects are not been save permanently in the realm database. i am able to see the data in my recycler view but when i restart the app, i am not able to see or read the data. it disappear which make me believe the data is not been saved in realm.

below is my code

 Realm realm = null;
        try { 
            realm = Realm.getDefaultInstance();//RealmController.getInstance().getRealm();
            realm.executeTransactionAsync(new Realm.Transaction() {
                @Override
                public void execute(Realm realm) {
                    Number num = realm.where(Income.class).max("id");
                    int nextId = (num == null) ? 1 : num.intValue() + 1;

                    Income income = realm.createObject(Income.class, nextId);
                    income.setIncomeAmount(amount.getText().toString());
                    income.setFrequency(frequency.getText().toString());
                    income.setDatePaid(datePaid.getText().toString());
                    income.setCategory(category.getText().toString());
                    income.setDepositTo(depositTo.getText().toString());
                    income.setDescription(description.getText().toString());
                    income.setStatus(getString(R.string.not_received));
                    realm.insertOrUpdate(income);
                }
            });
        } finally {
            if(realm != null) {
                realm.close();
            }
        }



import java.util.LinkedHashMap;
import java.util.Map;
import io.realm.Realm;
import io.realm.RealmObject;
import io.realm.RealmConfiguration;
import io.realm.annotations.PrimaryKey;

public class Income extends RealmObject {
    @PrimaryKey
    private int id ;
    private String category, amount, frequency, date, description, status, depositTo;

    public Income() {}

    public String getAmount() {
            return this.amount;
    }

    public void setIncomeAmount(String amount) {
            this.amount = amount;
    }
....
}

the following doesnt work either
realm.beginTransaction();
realm.copyToRealm(income);
realm.commitTransaction();

it looks like the data is save temporarily but not permanent. when i go to file exploer in android studio, i dont see realm file been created. can someone help why this is the case?