Has the allobjects () method in Java – realm been deprecated?

I'm trying to display list items in listview using realm offline database I followed some tutorials and he used the allobjects () method that I couldn't solve!

Can you help me?

This 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

You don't need that

realm. Replace allobjects (car. Class) with realm where(Car.class). findAll(). Specifically, allobjects is at 0.90 Deprecated in 0, at 0.91 0, see here

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>