Building your first Android application

Without further ado, let's explore how to create a simple Android application with Android Studio. We will be building the HelloApp. The HelloApp is an app that displays Hello world! on the screen upon the click of a button.

On the Android Studio landing screen, click Start a new Android Studio project. You will be taken to a screen where you will specify some details that concern the app you are about to build, such as the name of the application, your company domain, and the location of the project.

Type in HelloApp as the application name and enter a company domain. If you do not have a company domain name, fill in any valid domain name in the company domain input box – as this is a trivial project, a legitimate domain name is not required. Specify the location in which you want to save this project and tick the checkbox for the inclusion of Kotlin support.

After filling in the required parameters, continue to the next screen:

Here, we are required to specify our target devices. We are building this application to run on smartphones specifically, hence tick the Phone and Tablet checkbox if it's not already ticked. You will notice an options menu next to each device option. This dropdown is used to specify the target API level for the project being created. An API level is an integer that uniquely identifies the framework API division offered by a version of the Android platform.  Select API level 15 if not already selected and continue to the next screen:

On the next screen, we are required to select an activity to add to our application. An activity is a single screen with a unique user interface—similar to a window. We will discuss activities in more depth in Chapter 2, Building an Android Application – Tetris. For now, select the empty activity and continue to the next screen.

Now, we need to configure the activity that we just specified should be created. Name the activity HelloActivity and ensure the Generate Layout File and Backwards Compatibility checkboxes are ticked:

Now, click the Finish button. Android Studio may take a few minutes to set up your project. 
Once the setup is complete, you will be greeted by the IDE window containing your project files.

Errors pertaining to the absence of required project components may be encountered at any point during project development. Missing components can be downloaded from the SDK manager.

Make sure that the project window of the IDE is open (on the navigation bar, select View | Tool Windows | Project) and the Android view is currently selected from the drop-down list at the top of the Project window. You will see the following files at the left-hand side of the window:

  • app | java | com.mydomain.helloapp | HelloActivity.javaThis is the main activity of your application. An instance of this activity is launched by the system when you build and run your application:
  • app | res | layout | activity_hello.xml: The user interface for HelloActivity is defined within this XML file. It contains a TextView element placed within the ViewGroup of a ConstraintLayout. The text of the TextView has been set to Hello World!
  • app | manifests | AndroidManifest.xmlThe AndroidManifest file is used to describe the fundamental characteristics of your application. In addition, this is the file in which your application's components are defined.
  • Gradle Scripts | build.gradleTwo build.gradle files will be present in your project. The first build.gradle file is for the project and the second is for the app module. You will most frequently work with the module's build.gradle file for the configuration of the compilation procedure of Gradle tools and the building of your app.
Gradle is an open source build automation system used for the declaration of project configurations. In Android, Gradle is utilized as a build tool with the goal of building packages and managing application dependencies.
..................Content has been hidden....................

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