habib
habib

Reputation: 91

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?

Upvotes: 4

Views: 6113

Answers (5)

yash gandhi
yash gandhi

Reputation: 45

A layout defines all the appearance of an app and this is of no use without a java program which helps in real functioning of that visual display. Thus we define what an app does by writing its java code and a special java class called activity decides which layout to use at a particular instant and tells the app how to respond to the user.

Upvotes: 0

Ahmed Eid
Ahmed Eid

Reputation: 4804

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.

Upvotes: 5

Faruk Yazici
Faruk Yazici

Reputation: 2404

Briefly,

Activity is the java part of your projects. The program and any kind of algorithms are implemented here. Also layout views come to life in an activity.

Layout is where you organize the views in your page. But without activity, they have no meaning. Because in activity, you have to get these views and use them programmaticaly.

All together, you load views from layout to activity and in activies you implement your whole program.

Upvotes: 1

Fanuel Mpanje
Fanuel Mpanje

Reputation: 73

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.

Upvotes: 4

bluevoid
bluevoid

Reputation: 1349

An activity is the java code which attaches actions and puts content to/in a layout. For this the Activity loads the layout.

Upvotes: 1

Related Questions