What the Fragment? - Google I/O 2016

Android Developers · 108K views · 2016 · 28:53

Open on YouTube

Software architecture & designSoftware practice, open source & careerstalkdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about whether to use fragments, how the fragment back stack is restored, and how fragments fit into app architecture.

Recommended by 4 people across 4 different months, 2016 to 2018.

What it is

A 29-minute Google I/O 2016 session by Android Developers, led by Adam Powell, on when and how to use Android Fragments. It covers effective fragment use, treatment of fragments as part of an app's navigational state, and the API improvements and new use cases introduced that year.

What people said

Recommends Ali · 2016-07 · Stack Overflow · on “Fragments or multi activities”

This was a topic covered at Google I/O this year in a talk called What the Fragment [this video] . The basic rule is that if a feature is meant to be reused along with split mode in landscape or tablet, then definitely use a fragment. If the code is a reusable bit of functionality that may show up as a dialog or functionality in an other Activity then use a fragment. Something that is discouraged is the use of multiple fragments to piece together an activity. I've seen a fragment with nothing but a button embedded in multiple activities. That's not good. There is some discussion around how useful fragments are. Lyft came up with an alternate that uses views, called Scoop. If you want to swap a lo

Recommends user90766 · 2016-12 · Stack Overflow · on “Restoring fragment backstack for fragment with two possible backstack paths”

Found some answers in this excellent video by Android Developers + Adam Powell: Fragments: Google I/O 2016 [this video] In summary, Fragments and the Fragment BackStack are considered part of the navigational state of the app, so, as long as I don't mess with the backstack when the activity is launched, the OS will also restore the FragmentBackStack, thus the BackStack will know who launched C (A or B) even if the activity gets re-created. Thus, popBackStack will move from C to A or B as required.

Recommends Martin Marconcini · 2017-02 · Stack Overflow · on “Why does onAttach not recognize the correct instanceof context?”

@TwistedPurpose see updated answer, you need to read about how fragments work. I also suggest you watch [this video]

Recommends Bö macht Blau · 2018-01 · Stack Overflow · on “How can i initialize Room database from Presenter (MVP)”

There was a talk [this video] about Fragment s (Google I/O 2016) according to which Fragments are part of the ? in MV? (at about 9:30 min.) And Fragment s do have a Context as long as they are attached to an Activity . An interesting point of view. But if one insists on having an Android -free Presenter, then one can use an interface (or two): A Presenter needs an interface - let's call it ViewInterface - to communicate with the Fragment or Activity or View to which it belongs. Without this ViewInterface , nothing can happen in the "real world". The database (as a means of physically storing data and accessing stored data) is very much part of this "real world", so it is only fitting that the Pre

Cites Krzysztof Skrzynecki · 2017-01 · Stack Overflow · on “Fragment vs Support Fragment when targeting api 21 (Android 5.0) and above”

Android dashboards [LINK] show that only half of devices have Android 5.0 and above, but numbers look different for our customer data set - it's over 93% of our users. So we've decided to abandon support for devices with Android version lower than 5.0 and change minSdkVersion from 15 to 21. This upgrade require from us to review all of obsolete functionalities and clean some hacky workarounds which we applied to support older versions. One of main functionality which we can apply now is to replace android.support.v4.app.Fragment with android.app.Fragment . It sounds like good idea, especially when we know that fragment API had been reviewed and improved [this video] . Just to make sure that I’ll