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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Takahiro Shimokawa
April 23, 2015
Programming
5.2k
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Realm with ContentProvider
I tried to implement realm-java with ContentProvider.
Takahiro Shimokawa
April 23, 2015
More Decks by Takahiro Shimokawa
See All by Takahiro Shimokawa
PlayStoreでの新しいユーザー訴求 -LiveOpsの活用とその成果-
androhi
0
3k
ConcatAdapterを深掘る
androhi
1
500
Android Studio 4.1推しポイント!
androhi
0
1.5k
一人開発でつまづいたときの処方箋
androhi
0
410
Androidの物理ベースアニメーション
androhi
1
690
ConstraintLayout再入門
androhi
2
3.6k
Firebase Analytics 使用感
androhi
0
930
Support Library v23.2 overview
androhi
0
780
Support Library 総復習
androhi
2
2.6k
Other Decks in Programming
See All in Programming
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
120
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
730
ソフトウェアラスタライザ
fadis
1
730
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
5
550
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
430
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
290
React本体のコードリーディング
high_g_engineer
1
160
「人を評価する AI」の設計と実装
ryoyanara
0
260
FastAPI の並行処理モデルを完全に理解する
hoto17296
9
3.2k
Flow は今どうなっているか
mizdra
PRO
0
760
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
190
AI時代に学ぶ 好きなルール 嫌いなルール Linter編
shorty5121
0
200
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
432
67k
Amusing Abliteration
ianozsvald
1
270
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.6k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
630
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
350
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
900
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
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Λͦͷ··͏ͷ͕ྑͦ͞͏