I am learning android framework. I see these three get added when I add a new Blah.java basic activity. I would like to know what is the purpose of each one of it?
-
https://developer.android.com/guide/components/activities.html docsblah for activityblah, contentblah is blah that is displayedblah within your activityblah, https://developer.android.com/guide/components/fragments.html docsblah for fragmentblah. blah blah blah – Mohammed Atif Oct 14 '16 at 04:11
-
All that is nicely explained in the android documentation. – Henry Oct 14 '16 at 04:12
3 Answers
activity.xml
This xml file is design view of your activity. Its for designing purpose and also thats front end of screen view.you can design xml by using android layout and widgets.
fragment.xml
This xml file is design view of your fragments.
content.xml
Thats also part of activity.xml design file .we can access/use it from others xml file by using include
<include layout="@layout/content"/>

- 12,540
- 3
- 28
- 48
This are the layout xml for your android app, activity refers to your class, if you are using any fragment in your app then you should have one fragment.xml.
content is something which is optional, you can create anything inside content and then you can include that in both fragment and activity xml.

- 73
- 1
- 2
- 9
I am presuming you are using an IDE (Android Studio), which has this great advantage of generating layout files while creating Activities in android.
Now layout files (.xml) files are used for generating views, while creating an activity you are given a option (in IDE) whether you want to create a fragment for the activity.
For each of them the activities and fragments there will be a layout file and based on your activity/fragment name the layout files name will be generated (which can be edited)
In your case:
activity_blah.xml and content_blah.xml are the layout files generated for the blah.java activity file, you can add view components in the layout files for user interface of the activity
fragment_blah.xml is generated for fragment.

- 387
- 1
- 3
- 10
-
What is the need of creating a fragment for the activity, when the activity itself can do all things that fragment does? – sofs1 Oct 14 '16 at 06:27
-
lets say you have a listView in half of the screen and a webView in half, when you click on a listView item it loads a corresponding webView in the other half, with listView and webView each with a fragment. Bottom line: you can load two different fragments at the same time but with activity it can be only one screen at a time. [see this](http://stackoverflow.com/a/8597908/5689844) – Emdad Hossain Oct 14 '16 at 09:01
-
Thanks Hossain. I added my comments there http://stackoverflow.com/a/8597908/5689844 . Please reply there if possible. – sofs1 Oct 15 '16 at 03:47