
Android Programming for Beginners
By :

Now we can get started on the first app. In programming, it is tradition for the first app of a new student to use whatever language/OS they are using to say hello to the world. We will quickly build an app that does just that, and in Chapter 2, First Contact – Java, XML, and the UI Designer, we will go beyond that and add some buttons that respond to the user when they are pressed.
The complete code as it stands at the end of this chapter is in the download bundle in the Chapter 1
folder for your reference. You can't simply copy and paste this code, however! You still need to go through the project creation phase explained in this chapter (and at the beginning of all projects), as Android Studio does lots of work behind the scenes. Once you become familiar with these steps and understand which code is typed by you, the programmer, and which code/files are generated by Android Studio, you will then be able to save time and typing by copying and pasting the files I supply in the download bundle.
Follow these steps to start the project.
If you are prompted to Import Studio settings from…:, choose Do not import settings.
Hello World,
and the location for the files will be your AndroidProjects
folder that we created in the Setting up Android Studio section.Yourdomain.com
. If not, feel free to use gamecodeschool.com,
or something that you just make up yourself. It is only important when you come to publish.
Option |
Value entered |
---|---|
Application name: |
|
Company domain: |
|
Include C++ support |
Leave this option unchecked (see the next information box if you want to know more) |
Project location: |
|
Note that the application name has a space between "Hello" and "World," but the project location does not and will not work if it does.
The following screenshot shows the New Project screen once you have entered all the information:
You can write Android apps in a few different languages, including C++ and Kotlin. There are various advantages and disadvantages to each compared to using Java. Learning Java will be a great introduction to other languages, and Java is also the official language of Android. Most top apps and games on the Play Store are written in Java.
We already know that the Android SDK is the collection of packages of code that we will be using to develop our apps. Like any good SDK, the Android SDK is regularly updated, and each time it gets a significant update the version number is increased. Simply put, the higher the version number, the newer the features you get to use; the lower the version number, the more devices our app will work on. For now, the default API 15, Android 4.0.3 (Ice Cream Sandwich), will give us lots of great features and near 100% compatibility with the Android devices currently in use. If, at the time of reading, Android Studio is suggesting a newer API, then go with that.
If you are reading this some years in the future, then the Minimum SDK option will probably default to something different, but the code in this book will still work.
As a brief introduction, an Activity is a special class from the API and every Android app must have at least one. It is the part of the code in which our app will begin when it is launched by the user and handles interaction with the user. The options on this screen provide different ready-made templates of Activity class code to give programmers a fast start when creating various types of app. As we are starting from scratch, the most appropriate option for us is Basic Activity.
HelloWorldActivity
Android Studio will prepare our new project for us. This might take a few seconds or a few minutes, depending upon how powerful your PC is.
At this stage, you might be ready to proceed, but depending on the install process, you might need to click a couple of extra buttons.
This is why I mentioned that we are "probably" finished installing and setting up.
Look in the bottom window of Android Studio to see if you have the following message:
Note that if you do not see a horizontal window at the bottom of Android Studio like the one shown below, you can skip these two extra steps.
If you do, click Install missing platform(s) and sync project, accept the license agreement, and then click Next, followed by Finish.
If you get another message like this:
Click Install Build tools…. and then click Finish.
You can tidy up the screen a bit and close this bottom horizontal window by clicking the Messages tab on the very bottom of Android Studio, but this isn't compulsory.