1
Your First Android Application

This first chapter is full of new concepts and moving parts required to build an Android application. It is OK if you do not understand everything by the end of this chapter. You will be revisiting these ideas in greater detail as you proceed through the book.

The application you are going to create is called GeoQuiz. GeoQuiz tests the user’s knowledge of geography. The user presses TRUE or FALSE to answer the question on screen, and GeoQuiz provides instant feedback.

Figure 1.1 shows the result of a user pressing the TRUE button.

Figure 1.1  Do you come from a land down under?

Screenshot shows GeoQuiz screen on a mobile. Text reads, Canberra is the capital of Australia. True and False buttons are placed below. Popup text reads, Correct!

App Basics

Your GeoQuiz application will consist of an activity and a layout:

  • 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.

    GeoQuiz is a simple app, so it will have a single Activity subclass named QuizActivity. QuizActivity will manage the user interface, or UI, shown in Figure 1.1.

  • A layout defines a set of UI objects and their positions 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.

    GeoQuiz will include a layout file named activity_quiz.xml. The XML in this file will define the UI shown in Figure 1.1.

The relationship between QuizActivity and activity_quiz.xml is diagrammed in Figure 1.2.

Figure 1.2  QuizActivity manages what activity_quiz.xml defines

Illustration shows the relationship between QuizActivity and activity_quiz.xml.

With those ideas in mind, let’s build an app.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
44.223.40.255