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.3k
ConcatAdapterを深掘る
androhi
1
360
Android Studio 4.1推しポイント!
androhi
0
1.2k
一人開発でつまづいたときの処方箋
androhi
0
290
Androidの物理ベースアニメーション
androhi
1
550
ConstraintLayout再入門
androhi
2
3.4k
Firebase Analytics 使用感
androhi
0
850
Support Library v23.2 overview
androhi
0
640
Support Library 総復習
androhi
2
2.4k
Other Decks in Programming
See All in Programming
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.3k
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
3
1.2k
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
Ethereum_.pdf
nekomatu
0
470
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
940
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
250
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
The Cult of Friendly URLs
andyhume
78
6k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Code Reviewing Like a Champion
maltzj
520
39k
The Invisible Side of Design
smashingmag
298
50k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
For a Future-Friendly Web
brad_frost
175
9.4k
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Λͦͷ··͏ͷ͕ྑͦ͞͏