Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Realm storing int[] and String[]

Is there a way to store an int[] and a String[], other than creating a new object that contains those, and then storing it in a realmList

I have an object which takes the parameters of a String, int[], and String[]. you cant store int[], and String[] in realm so I made an object

public class Workouts extends RealmObject {

    private String workout;

    public Workouts() {

    }

    public Workouts(String workout) {
        this.workout = workout;
    }

    public String getWorkout() {
        return workout;
    }

    public void setWorkout(String workout) {
        this.workout = workout;
    }
}

and

public class Multiplier extends RealmObject {

    private int multiplier;

    public Multiplier() {

    }

    public Multiplier(int multiplier) {
        this.multiplier = multiplier;
    }

    public int getMultiplier() {
        return multiplier;
    }

    public void setMultiplier(int multiplier) {
        this.multiplier = multiplier;
    }
}

and then I store them like RealmList multipliers; RealmList workouts;

I am wondering if there is a way I can store these by just using an array instead of a RealmList

like image 688
Brady131313 Avatar asked Jan 24 '15 18:01

Brady131313


Video Answer


1 Answers

Emanuele from Realm here. Right now there's no other way other than wrapping String or int and use RealmList on those. This is for several reasons, including being able to use Realm file on different platforms. Is this an acceptable solution in your use-case or is it a pain?

If you would like, this gist demonstrates how one would use a RealmList to store a group of primitive values within a RealmObject. https://gist.github.com/cmelchior/1a97377df0c49cd4fca9

like image 66
Emanuelez Avatar answered Sep 20 '22 08:09

Emanuelez