Android FragmentsAndroid Fragment is the part of activity, it is also known as sub-activity. There can be more than one fragment in an activity. Fragments represent multiple screen inside one activity. Android fragment lifecycle is affected by activity lifecycle because fragments are included in activity. Each fragment has its own life cycle methods that is affected by activity life cycle because fragments are embedded in activity. The FragmentManager class is responsible to make interaction between fragment objects. Android Fragment LifecycleThe lifecycle of android fragment is like the activity lifecycle. There are 12 lifecycle methods for fragment. Android Fragment Lifecycle Methods
Android Fragment ExampleLet's have a look at the simple example of android fragment. activity_main.xmlFile: activity_main.xml File: fragment_fragment1.xml File: fragment_fragment2.xml MainActivity classFile: MainActivity.java File: Fragment1.java File: Fragment2.java Output:Next TopicAndroid Option Menu Example |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India