91-9990449935 0120-4256464 |
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 ExampleLet's have a look at the simple example of android fragment. activity_main.xmlFile: activity_main.xml
File: fragment1.xml
File: fragment2.xml
MainActivity classFile: MainActivity.java
File: Fragment1.java
File: Fragment2.java
Output:
Next TopicAndroid Option Menu Example
|