Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between layout and activity?

I have some problems with the layout and activity and I don't know are they different,are they related? I think the layout is a place we can add or remove our views and activity is just a place that shows any thing in our layout, is this true?

like image 347
habib Avatar asked Sep 21 '25 03:09

habib


2 Answers

An activity:

is an instance of Activity, a class in the Android SDK. An activity is responsible for managing user interaction with a screen of information. You write subclasses of Activity to implement the functionality that your app requires. A simple application may need only one subclass; a complex application can have many.

A layout:

defines a set of user interface objects and their position on the screen. A layout is made up of definitions written in XML. Each definition is used to create an object that appears on screen, like a button or some text.

like image 141
Ahmed Eid Avatar answered Sep 22 '25 17:09

Ahmed Eid


A layout deals with the user interface. Its where you set all your views that will be visible on the user interface.

The code behind (.java) sets the layout you created as the content view and manipulates the behavior of the views you have set. For example, sets the text for a text view.

The activity then is the whole thing, the layout and the code behind.

like image 31
Fanuel Mpanje Avatar answered Sep 22 '25 15:09

Fanuel Mpanje