Android Jetpack: How to smartly use fragments in your UI (Google I/O '18)

  Рет қаралды 102,513

Android Developers

Android Developers

6 жыл бұрын

With Architecture Components, the role of fragments has evolved. This session will explore the changing responsibilities of a fragment and talk about ongoing API changes.
Rate this session by signing-in on the I/O website here → goo.gl/ZT92Ef
Watch more Android sessions from I/O '18 here → goo.gl/R9L42F
See all the sessions from Google I/O '18 here → goo.gl/q1Tr8x
Subscribe to the Android Developers channel → goo.gl/GEh1ds
#io18 event: Google I/O 2018; re_ty: Publish; product: Android - Jetpack; fullname: Adam Powell, Ian Lake; event: Google I/O 2018;

Пікірлер: 97
@70ME3E
@70ME3E 6 жыл бұрын
I feel like I got nothing out of this about how exactly should one use em smartly
@nickadams2361
@nickadams2361 3 жыл бұрын
He is the worst speaker by far. The essence of what is wrong at Android
@albertbraun5351
@albertbraun5351 6 жыл бұрын
This talk gives us historical reasons for the invention of fragments, as well as their pros/cons. I found that helpful. Also, I liked the part (somewhere after 44:15) when Adam Powell says he thinks options menus should be deprecated and that android.app.FragmentManager actually is deprecated already. Yay.
@RS-kt6is
@RS-kt6is 6 жыл бұрын
what about SupportFragmentManager? :D
@maxchin2
@maxchin2 6 жыл бұрын
I think the title of this presentation should be called how fragment usage is affected by new components. The content of this presentation is all scattered to many topics. There is no new things from fragment.
5 жыл бұрын
9:16 kotlin doesn't have the keyword "new" :D
@agusavior_channel
@agusavior_channel 3 жыл бұрын
lol
@TheBlackManMythLegend
@TheBlackManMythLegend 2 жыл бұрын
@@agusavior_channel yeah,... google talk.. lol
@johnxina6996
@johnxina6996 2 жыл бұрын
lol, compiler should have showed the error
@Zissan
@Zissan 6 жыл бұрын
I am relatively new to Android (3 years so far). Fragment maybe not perfect, but it works for me. Why people hate fragment so much? I don't get it.
@omgpuppet
@omgpuppet 4 жыл бұрын
People just like to hate instead of weighing pros and cons logically.
@kasperfinne4514
@kasperfinne4514 6 жыл бұрын
So does the Navigation library supports having a backstack for each tab in a BottomNavigationView? Now that you recommend single Activity apps or is it still something we have to invent our self
@alondiskin5308
@alondiskin5308 6 жыл бұрын
How would you scale an ever evolving ui module,without the ability to break/encapsulate/apply SRP to it? how would you present a composite ui, showing different ui pieces of different app features,and stay life cycle aware? that's why fragments,or at least the concept of fragments is essential .Api wise i would prefer moving as much abstractions as possible to xml components, keep those ui controllers lean.
@Drizzle52693
@Drizzle52693 6 жыл бұрын
Was this conference set in the amazon rain forest?
@dhlehrenlos
@dhlehrenlos 6 жыл бұрын
Shoreline Amphitheatre
@kiryltuteishi
@kiryltuteishi 6 жыл бұрын
really, that's annoying
@sathishgadde1924
@sathishgadde1924 5 жыл бұрын
How to manage fragment state duting backstack. Like first contains recyclerview and user scroll to end then onitemclick navigate to second screen. now if user back to previous fragment there is not state managed. it is possible or not.if possible how to manage ?
@sarahpohler4149
@sarahpohler4149 5 жыл бұрын
How to change the transition from switching from a drawerlayout to a fragment? How to use the onNavigationItemSelected() with the android navigation component??? MORE EXAMPLES PLS!!!
@alexsag2151
@alexsag2151 6 жыл бұрын
Thank you!
@computerscience901
@computerscience901 5 жыл бұрын
Could you guys attach the slides to these presentations ?
@hasszhao
@hasszhao 6 жыл бұрын
Nav-framework doesn't do "share view(element)" transition. Need update.
@Zhuinden
@Zhuinden 6 жыл бұрын
7:51 Fragments, and "Retain objects across configuration changes"? You can retain the Fragment itself, but it doesn't have something like onRetainCustomNonConfigurationInstance. It's one of those things in the Fragment API that is hard to do, and which is why ViewModel exists.
@Zhuinden
@Zhuinden 5 жыл бұрын
43:44 if you don't like Fragments, write your own :D
@SHIVASURYA
@SHIVASURYA 6 жыл бұрын
I feel personally lot of bugs in fragment restoring after destroying.
@khalidhamid7448
@khalidhamid7448 6 жыл бұрын
@Android Developers Where can I get this ppt
@mos6581com
@mos6581com 6 жыл бұрын
RIP Blobmoji
@nicolassanta6324
@nicolassanta6324 6 жыл бұрын
Nice like it
@blockbusterlatefees7713
@blockbusterlatefees7713 5 жыл бұрын
I wish they had live code demos.
@typingcat
@typingcat 6 жыл бұрын
The music at the start is too loud compared to the voice volume.
@gaurav414u
@gaurav414u 6 жыл бұрын
How about maintaining the Toolbar in Single Activity Apps? How to have different toolbar styles for different fragments?
@alondiskin5308
@alondiskin5308 6 жыл бұрын
Fragments do provide a supporting behavior for that scenario, allowing you to manipulate the toolbar/actionbar menu, of the hosting activity.droidmentor.com/how-to-use-fragment-specific-menu-in-android/
@baieEtMotte
@baieEtMotte 6 жыл бұрын
Like everything in Android, Do It Yourself :).
@gaurav414u
@gaurav414u 6 жыл бұрын
Ha ha!
@nurhusni
@nurhusni 5 жыл бұрын
Where could I get that emoji shirt?
@hdkloh6857
@hdkloh6857 5 жыл бұрын
Remove the concept of fragments in android and make activity more functional n lighter...
@KasemJaffer
@KasemJaffer 6 жыл бұрын
This is all because the activity instance being destroyed and new one created. Why not fix Activity instead of adding a bunch of new classes (I know they are awesome but still ). Why not retain the activity instance on configuration changed?? I don't get it 😬
@IanLake
@IanLake 6 жыл бұрын
Android has, since the beginning, allowed you to handle configuration changes yourself. However, that involves you manually changing any resources (layouts, dimensions, etc) that differ between the separate configurations. That process is actually a lot more complicated and error prone assuming you are actually doing anything responsive (which you absolutely should) than just keeping your expensive data in a separate ViewModel object.
@KasemJaffer
@KasemJaffer 6 жыл бұрын
Ian Lake but if the Activity instance was retained we could just rebind our views from any viewmodel variable in the instance. I know this new viewmodel class is helpful for this case but wouldn't it be even better if the Activity instance is retained?
@IanLake
@IanLake 6 жыл бұрын
Kasem Saeed - that doesn't help you in needing to manually inflate a new layout associated with your new configuration or update the padding on every view that you use a @dimen variable on
@KasemJaffer
@KasemJaffer 6 жыл бұрын
Ian Lake That can always be taken from the resources inside onCreate method, no need to store it inside the viewmodel. The main issue I'm referring to is the complex variables , asynchronous tasks that is being destroyed along with the Activity. We had to handle that on our own just because the Activity is being destroyed.
@IanLake
@IanLake 6 жыл бұрын
Kasem Saeed - you need to handle one or the other. Reload every resource by hand or just store your data in something that survives and we'll reload your resources. One is a just a single line of code to access your ViewModel and a simple class, the other requires more and more work as your views and activities grow in complexity. Like I said, you have always been able to do it and for some apps, like a video player, you should definitely consider it. But there's a much, much, much higher chance of forgetting something and doing it wrong. There are specific lint checks to make it very difficult to do anything wrong with a ViewModel
@ragupatt
@ragupatt 6 жыл бұрын
Does that mean we don't have to bother with fragment transactions in most cases? This is great!
@LiranBarsisa
@LiranBarsisa 6 жыл бұрын
Does this shirt mean the blob-emojis might come back? One can only hope...
@witoldsienski1709
@witoldsienski1709 6 жыл бұрын
Google should choose activities or fragments!
@Actinesque
@Actinesque 6 жыл бұрын
Is it just me, or does Ian Lake look like Jimmy Hendricks from Silicon Valley?
@hdkloh6857
@hdkloh6857 5 жыл бұрын
Sometimes Google makes simple things more complex eg. Fragments
@damolaOnikoyi
@damolaOnikoyi 2 жыл бұрын
hehehe watching this in 2021, I have a lotta of catching up to do as a newbie
@70ME3E
@70ME3E 6 жыл бұрын
34:21 what is an "app chrome" in "common app chrome"? I googled it but nothing
@4RickB
@4RickB 5 жыл бұрын
Usually when they are talking about "app chrome" (and I've seen this in several of the Google I/O videos), they are talking about the common part of an app that doesn't change like the App Navigation Bar or a bottom navigation bar, etc. (The idea of "chrome" is that's it's the decoration around the changing UI screens.)
@bessermt
@bessermt 5 жыл бұрын
If a Fragment was designed to do everything an Activity does plus allow you to compose them, why didn't you just allow Activity to be composed? I'm not saying there isn't a good reason, but I would expect you to address this obvious question.
@user-yy3zf5hw2l
@user-yy3zf5hw2l 6 жыл бұрын
Still think fragment makes things even worse
@areebjamaliam
@areebjamaliam 6 жыл бұрын
But activity is horrible.
@alxkub
@alxkub 6 жыл бұрын
南风不竞 It’s not the idea of fragments that’s bad, it’s the API design made by Google is horrible.
@ap7467
@ap7467 6 жыл бұрын
Both have a different purpose
@whitecoder7119
@whitecoder7119 5 жыл бұрын
@@areebjamaliam without activity.. There no fragment.. 😋😋
@hdkloh6857
@hdkloh6857 4 жыл бұрын
Instead of fragments why don't you make activity lightweight....?
@dead_talash
@dead_talash 6 жыл бұрын
Does anyone still using Loaders?
@davideschembari3026
@davideschembari3026 6 жыл бұрын
good question :)
@thomash1576
@thomash1576 6 жыл бұрын
there is an approach for retaining your fragment states by using loaders ;- )
@Zhuinden
@Zhuinden 5 жыл бұрын
@@thomash1576 Which is crazy because it doesn't have onSaveInstanceState, therefore thankfully it was deprecated. I wish ViewModel had onSaveInstanceState...
@baieEtMotte
@baieEtMotte 6 жыл бұрын
Maybe it's time to make a mature API instead of making everything deprecated and changing paradigm at each iteration...
@AchrafAmil
@AchrafAmil 4 жыл бұрын
No. This is not how it works. I don't want a stagnating platform. It's ok to deprecate if you bring a better API.
@llothar68
@llothar68 4 жыл бұрын
@@AchrafAmil This is how iOS works. Some call it stagnation some call it stability. The base architecture should work 10 years after release. Android development sucks.
@PronabPal
@PronabPal 5 жыл бұрын
what a struggle to get the foundation right -to clean up the mess! .apparently just to help developers !
@shababkarim5907
@shababkarim5907 6 жыл бұрын
Will he get fined if he says "pain in the ass"?
@GaneshBhambarkar
@GaneshBhambarkar 6 жыл бұрын
I was thinking the same thing! In his place, I would have accidentally said "pain in the ass".
@0877adri
@0877adri 6 жыл бұрын
How to make instant apps, when all your app is in one activity with fragments ?
@IanLake
@IanLake 6 жыл бұрын
The important point is using the activity as the entry point to your app. For Instant Apps, you have multiple entry points (each separate feature), so multiple activities are totally in line with that recommendation.
@Zhuinden
@Zhuinden 6 жыл бұрын
You only need an Activity to enter the app, you can use that entry point to start your "main" activity with the right backstack and just swap out fragments in the main activity container
@anegine
@anegine 6 жыл бұрын
9:42 .replace(R.id.container, MyFragment()) not .replace(R.id.container, new MyFragment())
@techgo4431
@techgo4431 6 жыл бұрын
Eugene Kirzhanov have to get out of that Java habit lol
@davethomas1303
@davethomas1303 6 жыл бұрын
😂
@shoebmoin10
@shoebmoin10 6 жыл бұрын
Its kotlin dear
@hungnguyenmanh2069
@hungnguyenmanh2069 6 жыл бұрын
They talked a lot. I want they to describe in pictures
@thashilmaharaj9041
@thashilmaharaj9041 3 жыл бұрын
its 2021
@alxkub
@alxkub 6 жыл бұрын
Google keeps adding more and more ways to implement the same thing. This is literally road to hell!
@IanLake
@IanLake 6 жыл бұрын
The alternative is to keep the one complicated way of doing things. Creating a much simpler way of doing things and deprecating the old way is going to be a lot better for developers going forward. It just takes a while to get to that point.
@AndreRomano272
@AndreRomano272 6 жыл бұрын
Oh man you almost had me fooled, i thought you were being serious until you said 'horrible Android Studio'. :)
@davideschembari3026
@davideschembari3026 6 жыл бұрын
"horrible Android Studio"?! Compared to XCode which is just slightly more sophisticated than VI? The Android guys at Google are finally creating a consistent and usable way of doing things, rather than forcing us app devs to reinvent the wheel all the times.
@kamalamusa1315
@kamalamusa1315 2 жыл бұрын
PLEASE HELP ME 🙏🙏🙏🙏🙏🙏
@app_dev
@app_dev 5 жыл бұрын
What a confusing series of Google I/O. Each presentation is about same thing but nothing is clear.
@WillTesler
@WillTesler 6 жыл бұрын
I'd rather just use my own lightweight controller
@davethomas1303
@davethomas1303 6 жыл бұрын
I prefer to avoid fragments. medium.com/square-corner-blog/advocating-against-android-fragments-81fd0b462c97?source=linkShare-ae009bcd66b-1526096251 But perhaps the navigation framework with fragments won’t be so bad. I’m going to be giving fragments a second chance. Io18 “the rebirth of fragments; one of androids most conflicted components”
@robatoto
@robatoto 6 жыл бұрын
Fragments are far too complicated and broken. Stop adding new stuff on top of them. You’re building on sand. Create a simple yet powerful replacement that does not use fragments at all.
@IanLake
@IanLake 6 жыл бұрын
robatoto - we actually specifically mentioned that we want to get to the point where there's no magic in Fragments and you (or us) can build something totally new on top of those better signals. That's exactly what we've been doing with Lifecycle and ViewModels and more of that to come. If anything, we're removing more and more things from Fragments, not building on top of them
@Hamza-ny7rx
@Hamza-ny7rx 6 жыл бұрын
i love to ues fragment its plug and play
@janlukes5833
@janlukes5833 6 жыл бұрын
Then maybe you should not be a developer.
@baieEtMotte
@baieEtMotte 6 жыл бұрын
Whole of the Android SDK sucks. You have to write half an OS to make simple things. If you use Qt, Xamarin or something similar, you can develop at least 50% faster
@sarahpohler4149
@sarahpohler4149 5 жыл бұрын
@Ian Lake We need more exmaples. How to change the transition from switching from a drawerlayout to a fragment? How to use the onNavigationItemSelected() with the android navigation component? How we should use this if we don't know how?
@user-ci6zg5zy6b
@user-ci6zg5zy6b 6 жыл бұрын
我們的訊息者,題供專屬弧度示意,對
@jeghamaymen
@jeghamaymen 5 жыл бұрын
Switching to kotlin was a very lame move...
@eddieboston
@eddieboston 6 жыл бұрын
SHOW THE SLIDES!!! We don't care about these guys' faces. We want to see what's on the slides that they're talking about.
@dong4925
@dong4925 6 жыл бұрын
gay ?
@soma7891
@soma7891 4 жыл бұрын
Android Development sucks
@hba6018
@hba6018 Жыл бұрын
Ugly SDK, bad design, I dont know, maybe I vastly overestimate their engineers.
Understanding Android memory usage (Google I/O '18)
39:05
Android Developers
Рет қаралды 66 М.
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
МЯТНАЯ ФАНТА
Рет қаралды 11 МЛН
НЫСАНА КОНЦЕРТ 2024
2:26:34
Нысана театры
Рет қаралды 1,5 МЛН
Amazing weight loss transformation !! 😱😱
00:24
Tibo InShape
Рет қаралды 66 МЛН
How to Kotlin - from the lead Kotlin language designer (Google I/O '18)
39:24
Single activity: Why, when, and how (Android Dev Summit '18)
39:16
Android Developers
Рет қаралды 159 М.
Top 10 web things to know from Google I/O
6:10
Chrome for Developers
Рет қаралды 45 М.
Android Jetpack: What’s new in Android Support Library (Google I/O 2018)
33:52
Understand Kotlin Coroutines on Android (Google I/O'19)
37:49
Android Developers
Рет қаралды 174 М.
Flutter Engage
3:58:21
Flutter
Рет қаралды 1,7 МЛН
Improve app performance with Android Studio Profilers (Google I/O '18)
30:44
📱магазин техники в 2014 vs 2024
0:41
djetics
Рет қаралды 667 М.
Samsung laughing on iPhone #techbyakram
0:12
Tech by Akram
Рет қаралды 7 МЛН