112 Android Fragment Lifecycle Part 1 |

slidenerd · 166K views · 2013 · 8:33

Open on YouTube

Software (other)Software architecture & designtutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when someone is confused about how Fragment and Activity lifecycles interact, especially for the combined lifecycle diagram around 6:10.

Recommended by 2 people across 2 different months, 2013 to 2018.

What it is

A short Android tutorial from the slidenerd channel explaining the Fragment lifecycle (onAttach, onCreateView, onActivityCreated, onDestroyView, onDetach and so on). It walks through a diagram combining the Activity and Fragment lifecycles and the states a Fragment object passes through.

What people said

Recommends Kovács Imre · 2013-11 · Stack Overflow · on “Why things get different on Activity and fragment?”

Slow down. Fragments are tough to grasp and implement when you just got started. To get a better understanding work yourself through this guide [LINK] . Also make sure you experiment with this example project [LINK] . Both link to the official Android Developers site. EDIT: To get the basic picture, make sure you understand the Activity lifecycle and how this lifecycle connects to the Fragment lifecycle. To save yourself from frustration over getting stuck, watch this video [this video] and concentrate on the image at 6:10. If you want your Activity and Fragment objects to communicate smoothly, you will need to know when and where you can make method calls and callbacks. There's plenty of other u

Recommends mask · 2014-11 · Stack Overflow · on “Can some draw lifecycle of Fragment and its parent FragmentActivity?”

Take a look at the video link, he explains about how activity lifecycle mingle with fragment lifecycle. This helped me hope others will be helped too. [this video]

Cites Ederbit · 2016-01 · Stack Overflow · on “Null P Exception while setting CheckBox with Android Fragments”

Summary I thought i could create a CheckBox inside a Fragment and control it programmatically within the MainActivity. Check Link below for a tutorial. Fragments should be used to "modularize" an application. I thought to archieve this I could just put all the code in the MainActivity and have the UI Elements be set in the Fragment as I have very limited expierience with Java/Android. Generally the Fragment should take care of everything it possess itself. So heres what I did: In MainActivity.java I removed the Checkbox View and Reference. I then created a CheckBox inside the Fragment ( FragmentTest.java ) like so: public class FragmentTest extends Fragment{ View rootView; CheckBox FragmentC

Cites Zerato · 2018-08 · Stack Overflow · on “How to make a method communicate with both an Activity and a Fragment?”

I have an app consisting of (among other things) one Activity and one Fragment. In the Activity som data is displayed using TextViews, and in the Fragment the user can input some data using EditText-views. I have a method which takes data from both the Activity and Fragment, performs some calculations and finally displays a result in both the Fragment and the Activity. This method currently works when I call if after editing the text in any of the EditText-views in the Fragment. However, I also want to call it each time I update the data in the Activity but when I attempt this, I can not fetch the EditText data because they return null. So my question is: what is good practice, or the ”right