Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm Android - How can I convert RealmResults to array of objects?

Tags:

android

realm

I have an object

public class ArticleList extends RealmObject {

@PrimaryKey
private String id;
private String title;
private String subtitle;
private String image;
private String category;

}

What I want to do is to fetch result from Realm and them convert result to ArticleList[]

Fetch I do by using

RealmResults<ArticleList> results = realm.where(ArticleList.class).equalTo("category", "CategoryName").findAll();

What do I have to do next to get an array of objects ?

like image 695
Alexey K Avatar asked Mar 05 '16 11:03

Alexey K


People also ask

How to get an object from a realm?

You set everything properly in Realm schema, you store there the array, everything works great till now. Now, you fetch it from Realm and you get your object with the property which isn't array but an Object!

How to install realm on Android emulator?

Step 1: Go to Android Studio, open "Device File Explorer" from the right-side panel, and then select your emulator. Step 2: Get the Realm file for our app. For this, open the folder named data as highlighted above, and then go to the data folder again.

What is Android realm database?

Android Realm Database Tutorial. This is android realm database tutorial. Realm is an open source database that can be used to store data locally in android. It is used by over 100k developers and is a good alternative of SQLite.

Is there any reason not to use realm?

Big problem, for consideration to not use Realm. Imagine you have an object which has property of array of objects. You set everything properly in Realm schema, you store there the array, everything works great till now. Now, you fetch it from Realm and you get your object with the property which isn't array but an Object!


1 Answers

Simplest to convert into java ArrayList:

    ArrayList<People> list = new ArrayList(mRealm.where(People.class).findAll());
like image 174
Farhan Avatar answered Oct 18 '22 00:10

Farhan