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
Fragments
Search
Rafael Toledo
August 25, 2017
Programming
360
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Fragments
Apresentada na Android Dev Conference 2017
Rafael Toledo
August 25, 2017
More Decks by Rafael Toledo
See All by Rafael Toledo
Gamedev com Kotlin Native
rafaeltoledo
0
120
Kotlin Multiplataforma: Compartilhando código entre Android e iOS
rafaeltoledo
0
320
Motion Layout
rafaeltoledo
1
190
Pipeline Android
rafaeltoledo
3
210
Android Architecture Components
rafaeltoledo
7
230
What's New in Kotlin 1.3
rafaeltoledo
0
170
An Overview of Multiplatform Kotlin
rafaeltoledo
2
180
Compartilhando Código com Kotlin Multiplataforma
rafaeltoledo
2
300
Android Assíncrono
rafaeltoledo
3
250
Other Decks in Programming
See All in Programming
Heart of Swift Concurrency
koher
0
310
How I Stole PSI from Android Studio - DroidKaigi2026
worker8
0
110
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
220
AIとGame Jamで、ゲームを完成させた話
takahirosaeki
0
120
Laravelのアプリケーションをどこにデプロイするか #ツナギメオフライン.9
akase244
0
130
信頼性の目標を誰も求めてない
shubox
0
500
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
0
210
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
3
150
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
4
1.1k
Deep dive into the select statement (GopherCon UK)
jespino
0
180
iOS開発×AI駆動開発 〜最近使って便利だったスキルの話〜
nogu66
0
150
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
130
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
141
7.7k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
280
The SEO identity crisis: Don't let AI make you average
varn
0
550
Become a Pro
speakerdeck
PRO
31
6.2k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
530
How to Think Like a Performance Engineer
csswizardry
28
2.8k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.2k
So, you think you're a good person
axbom
PRO
2
2.2k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.3k
Transcript
FRAGMENTS Rafael Toledo @_rafaeltoledo
None
FRAGMENTS
None
POR QUE USAR FRAGMENTS?
POR QUE NÃO USAR FRAGMENTS?
LIFECYCLE
LIFECYCLE
LIFECYCLE
LIFECYCLE
LIFECYCLE
LIFECYCLE [CRIES IN ANDROIDISH]
WTF??? • IllegalStateException • getActivity() == null • executePendingTransactions() •
<fragment>
WTF???
EM 2017, VALE A PENA USAR FRAGMENTS?
EM 2017, VALE A PENA USAR FRAGMENTS?
DIFERENTES LAYOUTS, DIFERENTES TELAS
DIFERENTES TAMANHOS DE TELA
DIFERENTES TAMANHOS DE TELA Nexus One!
Quem usa tablet hoje em dia???
DIFERENTES TAMANHOS DE TELA Moto C (480x854) Samsung Galaxy S8+
(1440x2960)
DIFERENTES TAMANHOS DE TELA
Quem usa app em landscape???
Quem usa app em landscape??? EU!
ENCAPSULAMENTO DA NAVEGAÇÃO
ENCAPSULAMENTO DE NAVEGAÇÃO
ENCAPSULAMENTO DE NAVEGAÇÃO getSupportFragmentManager() .beginTransaction() .add(R.id.container, new Step1Fragment()) .addToBackStack(null) .commit();
// Back button = fragmentManager.popBackStack()
ENCAPSULAMENTO DE NAVEGAÇÃO getSupportFragmentManager() .beginTransaction() .add(R.id.container, new Step1Fragment()) .addToBackStack(null) .commit();
BACKSTACK? !=
BACKSTACK? Volta para a home
BACKSTACK?
BACKSTACK? Volta para a home?
BACKSTACK? Toolbar na Activity Fragment com conteúdo
BACKSTACK getSupportFragmentManager() .beginTransaction() .add(R.id.container, new Step1Fragment()) .addToBackStack(null) // ??? .commit();
BACKSTACK getSupportFragmentManager() .beginTransaction() .add(R.id.container, new Step1Fragment()) .addToBackStack("Cart") .commit();
BACKSTACK getSupportFragmentManager() .beginTransaction() .add(R.id.container, new Step1Fragment()) .addToBackStack("Cart") .commit(); fragmentManager.popBackStack("Cart"); fragmentManager.popBackStack("Cart",
FragmentManager.POP_BACK_STACK_INCLUSIVE);
STATEFUL DIALOGS
POR QUE EU PRECISO DE DIALOGS COM ESTADO?
MUDANÇAS DE CONFIGURAÇÃO
EVITANDO INTERAÇÕES DEAD-END
CUIDADO COM O DIALOG INFINITO
COMPONENTIZAÇÃO DA UI
COMPONENTIZAÇÃO DA UI Fragments como uma porção da Activity View
Fragment View Fragment Fragment Activity Fragment Activity
// Dentro do Fragment ((MainActivity) getActivity()).method(); COMPONENTIZAÇÃO DA UI -
DON'T!
// Dentro do Fragment ((MainActivity) getActivity()).method(); COMPONENTIZAÇÃO DA UI -
DON'T!
// Dentro da View ((MainActivity) context).method(); COMPONENTIZAÇÃO DA UI -
DON'T!
// Dentro da View ((MainActivity) context).method(); COMPONENTIZAÇÃO DA UI -
DON'T!
OLHA O REÚSO...
FALANDO EM VIEWS...
CUSTOM VIEWS x FRAGMENTS • Micro interações isoladas? Custom Views!
• Interação complexa, lida com rede, hardware, intents? Fragments! • View Pager? •Com interação rica (é uma tela de fato?) - Fragments! •Conteúdo simples (carrossel, vitrine, cards?) - Custom Views!
VOLTANDO...
COMO TROCAR DADOS ENTRE FRAGMENTS?
COMO TROCAR DADOS ENTRE FRAGMENTS? • EventBus?
COMO TROCAR DADOS ENTRE FRAGMENTS? • EventBus?
COMO TROCAR DADOS ENTRE FRAGMENTS? • EventBus? • Através da
Activity, implementando um listener
COMO TROCAR DADOS ENTRE FRAGMENTS? • EventBus? • Através da
Activity, implementando um listener • Architecture Components!
COMO TROCAR DADOS ENTRE FRAGMENTS? • EventBus? • Através da
Activity, implementando um listener • Architecture Components!
// No Fragment viewModel = ViewModelProviders.of(this) .get(MyViewModel.class); COMO TROCAR DADOS
ENTRE FRAGMENTS?
// No Fragment viewModel = ViewModelProviders.of(getActivity()) .get(MyViewModel.class); COMO TROCAR DADOS
ENTRE FRAGMENTS?
// No Fragment viewModel = ViewModelProviders.of(getActivity()) .get(MyViewModel.class); COMO TROCAR DADOS
ENTRE FRAGMENTS?
INICIALIZAÇÃO DE COMPONENTES
<fragment android:name="com.google.android.gms.maps.MapFragment" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" /> INICIALIZAÇÃO DE COMPONENTES
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); INICIALIZAÇÃO DE COMPONENTES
MapView mapView; @Override public void onCreate(Bundle savedInstanceState) { ... mapView
= findViewById(R.id.map); } INICIALIZAÇÃO DE COMPONENTES
@Override public void onStart() { super.onStart(); mapView.onStart(); } @Override public
void onStop() { mapView.onStop(); super.onStop(); } INICIALIZAÇÃO DE COMPONENTES
@Override public void onStart() { super.onStart(); mapView.onStart(); } @Override public
void onStop() { mapView.onStop(); super.onStop(); } INICIALIZAÇÃO DE COMPONENTES Boilerplate?
<fragment android:name="com.google.android.gms.maps.MapFragment" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" app:apiKey="1234567890abcdef" /> INICIALIZAÇÃO DE COMPONENTES
<fragment android:name="com.google.android.gms.maps.MapFragment" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" app:apiKey="1234567890abcdef" /> INICIALIZAÇÃO DE COMPONENTES
@Override public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) {
... } INICIALIZAÇÃO DE COMPONENTES
@Override public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) {
... } INICIALIZAÇÃO DE COMPONENTES
@Override public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) {
... } INICIALIZAÇÃO DE COMPONENTES
DICAS FINAIS • Sempre guarde estado dos seus Fragments! •
setRetainInstance(true) não deve ser usado para Fragments com Views! (Architecture Components usa!)
QUE TAL DAR UMA SEGUNDA CHANCE AOS FRAGMENTS?
Fragment Tricks youtube.com/watch?v=eUG3VWnXFtg What the Fragment? youtube.com/watch?v=k3IT-IJ0J98 Documentação developer.android.com/guide/components/fragments.html LINKS
Fragment Tricks youtube.com/watch?v=eUG3VWnXFtg What the Fragment? youtube.com/watch?v=k3IT-IJ0J98 Documentação developer.android.com/guide/components/fragments.html LINKS
Centro Av. Presidente Wilson, 231 - 29º andar (21) 2240-2030
Cidade Monções Av. Nações Unidas, 11.541 - 3º andar (11) 4119-0449 Savassi Av. Getúlio Vargas, 671 Sala 800 - 8º andar (31) 3360-8900 www.concrete.com.br speakerdeck.com/rafaeltoledo github.com/rafaeltoledo twitter.com/_rafaeltoledo