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
Parcerler
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
York Wu
January 18, 2017
Programming
0
75
Parcerler
GDG Kaohsiung 2017/01/18
York Wu
January 18, 2017
Tweet
Share
More Decks by York Wu
See All by York Wu
Clean Android Code for Unit Testing
yorkwu0318
0
65
Other Decks in Programming
See All in Programming
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
450
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
730
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.6k
CSC307 Lecture 08
javiergs
PRO
0
670
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
130
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
190
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
140
CSC307 Lecture 02
javiergs
PRO
1
780
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
180
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
230
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
280
AI & Enginnering
codelynx
0
110
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2.1k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
110
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.9k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.6k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
0
1.9k
Exploring anti-patterns in Rails
aemeredith
2
250
The Art of Programming - Codeland 2020
erikaheidi
57
14k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
450
Optimizing for Happiness
mojombo
379
71k
Tell your own story through comics
letsgokoyo
1
810
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Transcript
Parceler 2017/01/18 GDGK
Guideline Parcelable • Why use parcelable • How use parcelable
Parceler 簡介
Send string in an intent / bundle Intent intent =
new Intent(this, TargetActivity.class); intent.putExtra("intent_name", "york"); startActivity(intent);
send object in an intent / bundle Intent intent =
new Intent(this, TargetActivity.class); intent.putExtra("intent_user_data", userData); startActivity(intent);
Intent intent = new Intent(this, TargetActivity.class); intent.putExtra("intent_user_data", userData); startActivity(intent); send
object in an intent / bundle
send object in an intent / bundle Intent intent =
new Intent(this, TargetActivity.class); intent.putExtra("intent_user_data", userData); startActivity(intent);
Serializable http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html
Serializable 實作
Serializable 實作 Simplicity
Parcelable 實作
Parcelable 實作 boilerplate code
Serializable vs Parcelable http://www.developerphil.com/parcelable-vs-serializable/
Serializable vs Parcelable Serializable Parcelable 效能 低 高 維護性 高
低 用途 stream, file... intent / bundle
Other way? @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState);
UserData userData = MySingleton.getUserData();
Other way? @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState);
UserData userData = MySingleton.getUserData();
use global data (static) UserData userData = MySingleton.getUserData(); Benefit: •
easy to use • high performance
use global data (static) Disadvantage: • high coupling • can’t
handle activity life cycle (system kill)
Activity Life Cycle
Activity Life Cycle system kill
Activity Life Cycle Activity A MySingleton.setUserData(userData);
Activity Life Cycle Activity A Activity B UserData userData =
MySingleton.getUserData();
Activity Life Cycle Activity A Activity B UserData userData =
MySingleton.getUserData(); // userData is null After system kill
使用時機 • Intent / Bundle • Activity Life Cycle -
◦ system kill ◦ recreate
Activity Life Cycle recreate
Activity Life Cycle recreate onConfigurationChange • screen orientation • multiple-windows
• language change • ...
handle recreate @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState);
if (savedInstanceState != null) { userData = savedInstanceState.getParcelable(STATE_USER_DATA); } else { presenter.loadUserData(); } }
handle recreate @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelable(STATE_USER_DATA,
userData)); }
Parcelable 實作 - 純手動
Parcelable 實作 - 半手動 https://github.com/mcharmas/and roid-parcelable-intellij-plugin
Parcelable 實作 - 全自動 https://github.com/johncarl81/ parceler
Guideline Parcelable Parceler 簡介 • 基本用法 • 進階用法
Parceler 基本 用法 @Parcel
Parceler 基本用法 Parcels.unwrap() Parcels.wrap()
Parceler 基本用法 @Transient
Parceler 進階用法 @ParcelConverter
Parceler 進階用法 @ParcelConverter
Parceler 進階用法 @Parcel(analyze = DetailUserData.class)
更多用法 https://github.com/johncarl81/parceler
Q & A