realm java for android

43
Realm Java for Android Gokhan Arik Android Developer at Client Resources Inc. www.gokhanarik.com

Upload: gokhan-arik

Post on 23-Feb-2017

356 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Realm Java for Android

Realm Java for AndroidGokhan Arik

Android Developer at Client Resources Inc.

www.gokhanarik.com

Page 2: Realm Java for Android

What is Realm?

Replacement database for SQLite and CoreData

Cross platform mobile database

Founded by Alexander Stigsen and Bjarne Christiansen (former Nokia emp.)

Known as Tight DB in the past

100 million devices in 9 months

Page 3: Realm Java for Android

Switching to Realm

Page 4: Realm Java for Android

Why Realm?

faster than SQLite (up to 10x speed up over raw SQLite)

easy to use

object conversion

it is free

documentation and support

Page 5: Realm Java for Android

That’s why

Faster than SQLite (up to 10x speed up over raw SQLite)

Page 6: Realm Java for Android

That’s why

Faster than SQLite (up to 10x speed up over raw SQLite)

Page 7: Realm Java for Android

That’s why

Faster than SQLite (up to 10x speed up over raw SQLite)

Page 8: Realm Java for Android

That’s why

Faster than SQLite (up to 10x speed up over raw SQLite)

Please check out this article about Kevin Galligan’s concerns about the performance of Realm

http://kpgalligan.tumblr.com/post/133281929963/my-talk-at-droidcon-uk

Page 9: Realm Java for Android

That’s why

Easy to use (not this one, next one)

Page 10: Realm Java for Android

That’s why

Object conversion

Page 11: Realm Java for Android

That’s why

It is free

Page 12: Realm Java for Android

That’s why

Documentation and Support

Page 13: Realm Java for Android

How does it work?

Page 14: Realm Java for Android

Like this (as of version 1.0.0)

No Maven or Ant support

Supports Android since API Level 9 (Android 2.3 Gingerbread & above)

As of version 1.0.0 Eclipse is not supported

No need Proguard configuration. It is included in library

Page 15: Realm Java for Android

Like this (as of version 1.0.0)

Step 1: Add the following class path dependency to the project level build.gradle file.

Step 2: Apply the realm-android plugin to the top of application level build.gradle file

Page 16: Realm Java for Android

Like this (as of version 1.0.0)

Models

Page 17: Realm Java for Android

Like this (as of version 1.0.0)

Models

Page 18: Realm Java for Android

Like this (as of version 1.0.0)

Models

Page 19: Realm Java for Android

Like this (as of version 1.0.0)

Models - Auto-Update

Page 20: Realm Java for Android

Like this (as of version 1.0.0)

Models - Notifications

Page 21: Realm Java for Android

Like this (as of version 1.0.0)

Models - Primary Keys

Page 22: Realm Java for Android

Like this (as of version 1.0.0)

Relationships - Composition

Page 23: Realm Java for Android

Like this (as of version 1.0.0)

Relationships - Many to Many

Page 24: Realm Java for Android

Like this (as of version 1.0.0)

Writes

Page 25: Realm Java for Android

Like this (as of version 1.0.0)

Writes - Creating Objects

Page 26: Realm Java for Android

Like this (as of version 1.0.0)

Writes - Creating Objects

Page 27: Realm Java for Android

Like this (as of version 1.0.0)

Writes - Creating Objects

Page 28: Realm Java for Android

Like this (as of version 1.0.0)

Writes - Creating Objects

Page 29: Realm Java for Android

Like this (as of version 1.0.0)

Queries

Page 30: Realm Java for Android

Like this (as of version 1.0.0)

Queries - Conditions

Page 31: Realm Java for Android

Like this (as of version 1.0.0)

Queries - Sorting

Page 32: Realm Java for Android

Like this (as of version 1.0.0)

Queries - Chaining Queries

Page 33: Realm Java for Android

Like this (as of version 1.0.0)

Queries - Async Queries

Page 34: Realm Java for Android

Like this (as of version 1.0.0)

Queries - Async Queries

Page 35: Realm Java for Android

Like this (as of version 1.0.0)

Realms - Default Configuration

Page 36: Realm Java for Android

Like this (as of version 1.0.0)

Realms - Multiple Configuration

Page 37: Realm Java for Android

Like this (as of version 1.0.0)

Realms - Closing Instances

Page 38: Realm Java for Android

Like this (as of version 1.0.0)

JSON

Page 39: Realm Java for Android

Like this (as of version 1.0.0)

Android - Intents

Page 40: Realm Java for Android

Like this (as of version 1.0.0)

Android - Async Task

Page 41: Realm Java for Android

Like this (as of version 1.0.0)

Android - Debugging

Page 42: Realm Java for Android

Final Notes

perform all Realm write operations on a background thread (not Android’s main thread)

RealmObjects and RealmResults access all the data they refer to lazily. For this reason it is important to keep the Realm instance open for as long as you want to access your Realm objects or query results

Page 43: Realm Java for Android

References

http://kpgalligan.tumblr.com/post/133281929963/my-talk-at-droidcon-uk

http://realm.io

https://gist.github.com/cmelchior/1a97377df0c49cd4fca9