Difference between Activity and Content

Asked

Viewed 490 times

6

I do not know if this is the right place for this, if it is not for guidance where I take this doubt. I’m learning to develop apps in Android Studio, and I’m following some tutorials. Some cases I’ve noticed that some have just activity and others besides the activityalso has contentwhich is the case with this:

inserir a descrição da imagem aqui

and in this only the Activity

inserir a descrição da imagem aqui

Whenever I create a project it never generates the context. I would like to know what is the difference of both and its purpose. and if you need to have the context.

2 answers

2


When you create a Basic Activity it creates the xml of activity and of content together, this model already comes with a FABButton along with the layout so it creates 2 files the ideal is to use the content to put other components so the functioning of FABButton is not affected.

If you don’t want him to create this template always just select the Empty Activity when creating a new.inserir a descrição da imagem aqui

I hope it helps you.

  • All right William I think I got it now, this FABButtonwould be the back button?

  • No, it is a circular button that when you create Basic Activity is already added in your xml with the Activity click event

  • In the case of this one appearing in this first activity of the image you posted, a Basic Activity?

  • Exactly...!!

2

What you refer to are just file names of layout.

A layout can be used by a Activity or not.
Among others, they are used in Activities, Fragments, Listview’s or Recyclerview’s items.

A file of layout may also use other files as an integral part of it, i.e., parts of a layout may be in other layout.

This is the case (I believe) of the first example that refers: the file(layout) content_primeira.xml is used in the file(layout) activity_primeira.xml.

The inclusion of layout files in one another is done with the use of tag <include>.

If you go see the xml of activity_primeira.xml you will find a line with the following content

<include layout="@layout/content_primeira"/>

An advantage of this approach is possibility of a file/xml/layout be used in more than one layout.

  • Thanks for the ramaral explanation, opened a little more the mind.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.