Blakes 21 Days Chapter 21 Document


Day 21, Writing Android Apps with Java

The History of Android

Writing an Android App

Figure 21.1 - Choosing the user interface theme in Android Studio - goes here

456 21.1

First Program

Figure 21.2 - Starting a new Android project in Android Studio - goes here

458 21.2
  1. In the Application Name field, enter Palindrome.
  2. In the Company Domain field, enter java21days.com or a domain name that you own.
  3. The Project Location field indicates the folder where project files will be stored.
  4. Click Next. You'll be asked which type of Android devices to target with your app.
  5. The Minimum SDK field determines the oldest version of Android OS that can run the app.
  6. You are asked whether to create an Activitym which is a class that performsa task.
  7. This activity must be customized.
  8. Click Finish.

Organizing an Android Project

Figure 21.3 - Viewing the components of an Android project. -- goes here

460 21.3

Creating the Program

Figure 21.4 - Creating an app's string resources. - goes here

464 21.4

Figure 21.5 - Editing an app's string resources as an XML file. - goes here

466 21.5

Running the App

Figure 21.6 - Running an app in an emulator. - goes here

468 21.6
Output

Error: x86 emulation currently requires hardware acceleration:
Please ensure Intel HAXM is properly installed and usable. CPU
acceleration status: HAX kernel module is not installed

Designing an Android App

Preparing Resources

Figure 21.7 - Examining an app's resources. - goes here

470 21.7

Configuring a Manifest File

Figure 21.8 - Editing an app's AndroidManifest.xml file. - goes here

472 21.8

Designing the Graphical User Interface

Figure 21.9 - Editing an activity's graphical user interface. - goes here

474 21.9

Figure 21.10 - Viewing an app's user interface. - goes here

476 21.10

Writing Code

Listing 21.1 The Starting Text of SantaActivity.java

The Explanation & further instructions

(Second Program) Listing 21.2 The Full Text of SantaActivity.java

Running the App

Figure 21.11 - Calling Santa Claus. - goes here

471 21.11

Figure 21.12 - Running your app on a real Android phone. - goes here

480 21.12

Summary

Q & A

Quiz - Questions

  1. 593 What Android object enables an app to communicate with the device running the app ?
    1. Intent
    2. View
    3. Activity
  2. 593 Which resource file contains an app's string resources ?
    1. main.xml
    2. strings.xml
    3. R.java
  3. 593 Can an app have resource files named icon.gif and icon.png ?
    1. Yes
    2. No
    3. Ask again later.

Answers

  1. A. The Intent also can be used for one Activity to tell another to take an action.
  2. B. The main.xml file is a screen, and R.java defines resource IDs.
  3. B. No, because both files would be given the same identifier, icon.

Certification Practice

  1. 594 What will be the value of x when it is displayed ?
    1. 9.0
    2. 10.0
    3. 11.0
    4. The program will not compile.

Exercise