Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Parcerler
Search
York Wu
January 18, 2017
Programming
77
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Parcerler
GDG Kaohsiung 2017/01/18
York Wu
January 18, 2017
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
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
170
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
410
Agents on Rails - Rails at Scale 2026
irinanazarova
0
560
ジョジョの世界をXRで再現する
mofurune
0
160
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
JIS keyboard support in Omarchy
lef237
0
110
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
420
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
The Rails Doctrine Decade
koic
2
590
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
The browser strikes back
jonoalderson
0
1.8k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.2k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
Abbi's Birthday
coloredviolet
4
10k
Discover your Explorer Soul
emna__ayadi
2
1.3k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
A better future with KSS
kneath
240
18k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
The untapped power of vector embeddings
frankvandijk
2
1.9k
Being A Developer After 40
akosma
92
590k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
570
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