Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Realm with ContentProvider
Search
Takahiro Shimokawa
April 23, 2015
Programming
8
5.1k
Realm with ContentProvider
I tried to implement realm-java with ContentProvider.
Takahiro Shimokawa
April 23, 2015
Tweet
Share
More Decks by Takahiro Shimokawa
See All by Takahiro Shimokawa
PlayStoreでの新しいユーザー訴求 -LiveOpsの活用とその成果-
androhi
0
2.7k
ConcatAdapterを深掘る
androhi
1
440
Android Studio 4.1推しポイント!
androhi
0
1.3k
一人開発でつまづいたときの処方箋
androhi
0
360
Androidの物理ベースアニメーション
androhi
1
630
ConstraintLayout再入門
androhi
2
3.5k
Firebase Analytics 使用感
androhi
0
910
Support Library v23.2 overview
androhi
0
700
Support Library 総復習
androhi
2
2.5k
Other Decks in Programming
See All in Programming
Advance Your Career with Open Source
ivargrimstad
0
240
defer f()とdefer fの挙動を 誤解していた話
kogamochiduki
2
160
LLMとPlaywright/reg-suitを活用した jQueryリファクタリングの実際
kinocoboy2
4
660
Django Ninja による API 開発効率化とリプレースの実践
kashewnuts
0
850
10年もののAPIサーバーにおけるCI/CDの改善の奮闘
mbook
0
670
Repenser les filtres API Platform: une nouvelle syntaxe
vinceamstoutz
2
160
私達はmodernize packageに夢を見るか feat. go/analysis, go/ast / Go Conference 2025
kaorumuta
2
430
CSC509 Lecture 03
javiergs
PRO
0
320
Web技術を最大限活用してRAW画像を現像する / Developing RAW Images on the Web
ssssota
2
1.1k
Serena MCPのすすめ
wadakatu
4
850
気づいて!アプリからのSOS 〜App Store Connect APIで始めるパフォーマンス健康診断〜
waka12
0
260
AccessorySetupKitで実現するシームレスなペアリング体験 / Seamless pairing with AccessorySetupKit
nekowen
0
210
Featured
See All Featured
The Invisible Side of Design
smashingmag
301
51k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Agile that works and the tools we love
rasmusluckow
331
21k
Raft: Consensus for Rubyists
vanstee
139
7.1k
Automating Front-end Workflow
addyosmani
1371
200k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
BBQ
matthewcrist
89
9.8k
The Art of Programming - Codeland 2020
erikaheidi
56
14k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
950
The Language of Interfaces
destraynor
162
25k
Visualization
eitanlees
148
16k
Transcript
Realm with ContentProvider Realm meetup #2
About me 4 Լ ܟ߂ (@androhi) 4 גࣜձࣾZaim (AndroidΞϓϦ୲) 4
DroidKaigiͰൃද͠·͢ 4 JellyBeanͱKitKatͰ࣮ݱ͢ΔϚςϦΞϧσβΠϯ
Tried ContentProviderͰΞΫηε͢ΔDBΛɺRealmʹͯ͠Έ·͠ ͨ Reason AndroidͷSyncAdapterΛͬͨࣗಈಉظͷΈͰɺό οΫάϥϯυͰಉظॲཧΛ͢ΔࡍʹContentProviderΛ༻ ͍Δͱ͍͏ϧʔϧ͕͋ΔͨΊ
None
Extend ContentProvider 1. Queryϝιουͷ࣮ (+ ಠࣗCursorͷੜ) 2. Insertϝιουͷ࣮ 3. Updateϝιουͷ࣮
4. Deleteϝιουͷ࣮ 5. BulkInsertϝιουͷ࣮
This time 1. Queryϝιουͷ࣮ (+ ಠࣗCursorͷੜ) 2. Insertϝιουͷ࣮ 3. Updateϝιουͷ࣮
4. Deleteϝιουͷ࣮ 5. BulkInsertϝιουͷ࣮
1-1. Create cursor static final String[] sColumns = new String[]
{"_id", "name", "price"}; RealmQuery<Item> query = mRealm.where(Item.class); RealmResults<Item> results = query.findAll(); MatrixCursor matrixCursor = new MatrixCursor(sColumns); for (Item item : results) { Object[] rowData = new Object[]{item.get_id(), item.getName(), item.getPrice()}; matrixCursor.addRow(rowData); }
1-2. Implement query @Override public Cursor query(Uri uri, String[] projection,
String selection, String[] selectionArgs, String sortOrder) { ... RealmQuery<Item> query = mRealm.where(Item.class); RealmResults<Item> results = query.findAll(); MatrixCursor matrixCursor = new MatrixCursor(sColumns); for (Item item : results) { Object[] rowData = new Object[]{item.get_id(), item.getName(), item.getPrice()}; matrixCursor.addRow(rowData); } return matrixCursor; }
2. Implement insert @Override public Uri insert(Uri uri, ContentValues contentValues)
{ ... mRealm.beginTransaction(); Item item = mRealm.createObject(Item.class); item.set_id(++count); item.setName(contentValues.getAsString(sColumns[1])); item.setPrice(contentValues.getAsLong(sColumns[2])); mRealm.commitTransaction(); return Uri.withAppendedPath(uri, String.valueOf(item.get_id())); }
5. Implement bulkInsert @Override public int bulkInsert(Uri uri, ContentValues[] values)
{ ... mRealm.beginTransaction(); try { for (ContentValues value : values) { Item item = mRealm.createObject(Item.class); item.set_id(value.getAsLong(sColumns[0])); item.setName(value.getAsString(sColumns[1])); item.setPrice(value.getAsLong(sColumns[2])); } } finally { mRealm.commitTransaction(); } return values.length; }
compare with SQLite Query/Insert -> 10,000݅ Xperia Z1f (Android 4.4.2)
SQLite with ContentProvider 4 Insertɺ͔ͳΓ͍ 4 Query͕ૣ͍
Realm with ContentProvider 4 Insert͕ɺͦΜͳʹ͘ͳ͍ 4 Query͕SQLiteʹൺΔͱ͍ ʢCursorੜͷӨڹʣ 4 BulkInsertޓ֯ʁ
None
None
None
Summary 4 ύϑΥʔϚϯεམͪΔʢʁʣ͚ͲContentProviderͰ ͑Δ 4 Queryϝιουվળͷ༨͕͋Γͦ͏ 4 ࣗಈಉظ͚ͩContentProviderܦ༝ʹ͠ɺΞϓϦຊମ RealmΛͦͷ··͏ͷ͕ྑͦ͞͏