Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is allObjects() method in Realm was deprecated?

I'm trying to display list items in a ListView using Realm offline database. I followed some tutorial and he used allObjects() method that cannot be resolved with me!!

Can you help me in this?

Here is my code:

@Override
protected void onResume() {
    super.onResume();

    Realm.init(getApplicationContext());
    RealmConfiguration config = new RealmConfiguration.
            Builder().
            deleteRealmIfMigrationNeeded().
            build();
    Realm.setDefaultConfiguration(config);

    Realm realm = Realm.getInstance(config);
    realm.beginTransaction();
    List<Car> cars = realm.**allObjects**(Car.class);
    String[] names = new String[cars.size()];
    for(int i=0; i<names.length;i++){
        names[i]=cars.get(i).getName();
    }

    ListView listView = (ListView)findViewById(R.id.listView);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,names);
    listView.setAdapter(adapter);
}
like image 790
dif_jeff Avatar asked Oct 15 '25 16:10

dif_jeff


1 Answers

realm.beginTransaction();

You don't need that.

List<Car> cars = realm.**allObjects**(Car.class);

realm.allObjects(Car.class) was replaced with realm.where(Car.class).findAll(). Specifically, allObjects was deprecated in 0.90.0, and removed in 0.91.0, see here.

like image 141
EpicPandaForce Avatar answered Oct 18 '25 05:10

EpicPandaForce



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!