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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
200
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
AI & Enginnering
codelynx
0
110
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
100
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
130
Basic Architectures
denyspoltorak
0
670
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
270
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
690
2026年 エンジニアリング自己学習法
yumechi
0
130
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
2.5k
AI巻き込み型コードレビューのススメ
nealle
1
220
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
200
Featured
See All Featured
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
66
37k
Odyssey Design
rkendrick25
PRO
1
490
BBQ
matthewcrist
89
10k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
A better future with KSS
kneath
240
18k
Paper Plane (Part 1)
katiecoart
PRO
0
4.2k
The untapped power of vector embeddings
frankvandijk
1
1.6k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
110
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
940
Agile that works and the tools we love
rasmusluckow
331
21k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
120
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