Realm中的allObjects()方法是否已被弃用?

dif*_*ide 3 java android realm

我正在尝试使用Realm离线数据库在ListView中显示列表项.我按照一些教程,他使用了无法与我解决的allObjects()方法!

你能帮帮我吗?

这是我的代码:

@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);
}
Run Code Online (Sandbox Code Playgroud)

Epi*_*rce 8

realm.beginTransaction();

你不需要那个.

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

realm.allObjects(Car.class)被替换为realm.where(Car.class).findAll().具体来说,allObjects在0.90.0中弃用,在0.91.0中删除,请参见此处.