---
title: "Integrate Realm in android application"  
description: "Integrate Realm in android application"  
author: "Kyle Flores"  
published: 2017-01-09  
updated: 2023-06-27  
canonical: https://www.mindstick.com/forum/34237/integrate-realm-in-android-application  
category: "android"  
tags: ["android"]  
reading_time: 2 minutes  

---

# Integrate Realm in android application

Hi everyone, I have been working on a [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) related to [android app](https://www.mindstick.com/articles/208957/a-complete-guide-for-android-app-development) and want to know how to integrate realm in [android application](https://www.mindstick.com/forum/33405/how-to-get-the-build-version-number-of-your-android-application). I am also very curious about various other php [questions and answers](https://www.mindstick.com/blog/12714/pass-ibm-c2090-101-2019-march-exam-easily-with-questions-and-answers-pdf) Because I so got stuck in some coding issues, did is why I [am looking](https://answers.mindstick.com/qa/115463/i-am-looking-for-to-joining-the-mindstick-internship-program-how-to-apply) for a search [platform](https://www.mindstick.com/articles/13080/wikipedia-the-most-powerful-advertising-platform-of-the-digital-age) where the [evolving](https://answers.mindstick.com/qa/50606/which-is-the-most-successful-and-evolving-mammal-of-the-animal-kingdom) [community](https://yourviews.mindstick.com/view/87457/khalistan-community-a-threat-to-india) can help me to resolve my queries.

## Replies

### Reply by Aryan Kumar

Sure, here are the steps on how to integrate Realm in an [Android](https://www.mindstick.com/articles/13046/10-reasons-why-i-prefer-android-vs-iphone-ios) application:

1. **Add the Realm dependency to your project.** You can add the dependency to your project's build.gradle file.

Code snippet

```plaintext
dependencies {
    implementation 'io.realm:realm-android:10.10.1'
}
```

1. **Initialize Realm in your application.** You can do this by calling the `Realm.init()` method in your application's `onCreate()` method.

Code snippet

```plaintext
public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        Realm.init(this);
    }
}
```

1. **Create a Realm instance.** You can create a Realm instance by calling the `Realm.getDefaultInstance()` method.

Code snippet

```plaintext
Realm realm = Realm.getDefaultInstance();
```

1. **Use Realm to store and retrieve data.** You can use Realm to store and retrieve data by creating Realm objects. Realm objects are similar to Java objects, but they are stored in Realm's database.

Here is an example of how to create a Realm object:

Code snippet

```plaintext
public class Person extends RealmObject {

    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
```

To store a Realm object, you can call the `save()` method on the Realm instance.

Code snippet

```plaintext
realm.save(person);
```

To retrieve a Realm object, you can call the `where()` method on the Realm instance and pass in a query.

Code snippet

```plaintext
RealmResults<Person> persons = realm.where(Person.class).findAll();
```

1. **Close the Realm instance.** When you are finished using Realm, you should close the Realm instance. This will free up resources and prevent memory leaks.

Code snippet

```plaintext
realm.close();
```


---

Original Source: https://www.mindstick.com/forum/34237/integrate-realm-in-android-application

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
