Just Maths - Android Activities and Layouts
Let's start creating our first app - Just Maths. This will be a small app to introduce you to the various aspects of Android App Development - starting with activities and layouts. So just jump right in.
What is Activity?
Activity is just a single screen. Yes it is that simple. So in our case - Main Menu Screen is one activity, Game Screen is another activity and Score Screen is another activity. Activity is a screen that displays some information to the user or requires some input from the user. Activity handles the interaction with the user.
In general, every screen in an app is Activity which is a subclass of Activity Class defined in android.app package provided as part of Android SDK.
In general, every screen in an app is Activity which is a subclass of Activity Class defined in android.app package provided as part of Android SDK.
What is Layout?
Now we know what are activities. Layout defines how your activity looks. Your activity displays textboxes, labels, drop-downs, images etc. How these objects are arranged and displayed on the screen is managed by a layout file. This layout file is an XML file in which you define the controls required for the screen.
How your screen looks is defined by this layout file.
How your screen looks is defined by this layout file.
Android creates activity object and calls its onCreate() method for you. You can think of onCreate() as its constructor where all the initialization is done.
Layout is assigned to an activity in onCreate() by calling a method named setContentView(LayoutId). Refer below screenshot.
CheezyCode - Activity Code View |
To summarize,
Activity handles the interaction with the user and tells what to do when something occurs (for instance, when you press the button). Every activity inherits from android.app.Activity and onCreate() is the method which is called after activity object is created.
Layout is an XML resource which has an ID. In fact, every resource in the resources folder has ID which is used to access them in Java code. This layout file defines the appearance of the activity and defines how all the controls are placed. Controls are Views and ViewGroups. ViewGroups are the containers or the layout managers.
Let us know if you have any query. Happy reading.
WhatsApp Status Video
ReplyDeleteHi There! Android developer @ cheezycode .
ReplyDeleteActually i like your way of explanation and i think you're the best on YouTube and i am lucky that i found you.
But i have a request that i want to learn full android app develepement like making complicated apps , admob integration, in app purchase , conneting app to the server etc. So i want a teacher and i think that you are the best so please if you can provide me full learning classes and i am ready to pay for your precious time .
Or you can provide me recorded lectures . Also please share your mail id .
And please reply soon.
Great
ReplyDelete