Java – Is the allObjects() method deprecated in Realm?

Is the allObjects() method deprecated in Realm?… here is a solution to the problem.

Is the allObjects() method deprecated in Realm?

I’m trying to use a Realm offline database to display list items in a ListView. I followed some tutorials and he used the allObjects() method that I couldn’t solve!!

Can you help me?

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);
}

Solution

realm.beginTransaction();

You don’t need that.

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

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

Related Problems and Solutions