Has the allobjects () method in Java – realm been deprecated?
•
Java
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
二维码