Wednesday, December 2, 2015

We develop applications for Android: Hello World! – Androidinsider (press release) (blog)


We continue to get acquainted with the world of application development for Android. If you carefully follow the steps outlined in the first article of this series, then your computer has all the necessary tools to develop and they are ready to go. In this section we’ll write «Hello World!». Since this has to start every young designer.

Starting a new project


We need to run Android Studio. Before you start a new project, we make sure that all the steps in the first part were executed correctly and all the required components are installed. To do this on the home page Android Studio we go to the tab Configure .


Next, open SDK Manager .


In the window that opens Make sure you have installed Android SDK.


Now we can close the window and return to the start page of Android Studio. It interests us first tab Start a new Android Studio project . Enter a name for the future application and domain name, then you can go to the next step.


In the next window that opens, we need to decide which type of devices we will develop the application. For the first time proposes to limit the development of smartphones and tablets, and therefore we need a check mark in the very first tab. However, do note that with Android Studio you can also develop for Android Wear, Android TV, Android Auto and even for Google Glass.

In this window we will need to select the Minimum SDK . In this field, we select the oldest supported version of Android. Why the developers can not select all the version of Android, since 1.1? Because the possibility of applications from older versions of rather limited. Therefore I propose to leave this field your proposed version and go to the next page.

On this page, we choose the appearance of the main screen of our future applications. You have proposed several templates. Perhaps you want on each screen of your app flaunted its own unique interface, but if you’re happy with the way the interface sees Android-application of Google, for you to work a little easier. It is worth noting that you can choose from different templates for different application screens, but first we choose Blank Activity .


On the next page, we asked to choose a name for the screen and the layer. It is necessary to choose the logical name is to streamline and simplify the process of writing to the developer of the application. Today, we are satisfied with things as they are. We can click Finish and watch as a window of our application.

Getting to the point


Newly developers often want to write in the middle of the screen app ” Hello World! ». To do this we need to edit content_main.xml , which contains the selected contact layer. Find the layer you can in the box on the left. It is located in the directory app & gt; res & gt; content_main.xml .


Android Studio will show you the code for XML, and how you are editing the layer will look like on the device. In the folder Widgets you can see the items that can be added to an editable application screen. If we need to add one of these elements, you can simply drag them on the screen of the device.


Let us therefore add the “OK” button directly below the inscription «Hello World!».


In the lower right corner you can edit the text that appears on the button, and her ID. Let in the text write «Hello World!», And the existing inscription on the screen to remove, highlight it in the visual editor. You can also play around with the settings you created the button.


Now, let’s open the tab and add a bit of code. We will do it immediately after the closing brace «} » and the text “Override, Public Boolean “. Let’s write this text:

public void buttonOnClick (View v) {

Button button = (Button) v;

((Button) v) .setText («Hello!»);


It will allow us to change the text by pressing the button .


At the beginning of the page you will find the word import … . Make sure there is a line in the list of import android.widget.Button; , and add it if you did not find per se.


Now we can return to the tab content_main. xml and click on the button. In the lower right corner of the field we choose onClick , which places a value for buttonOnClick . So we tie our written code to the button that interests us.

Running the Application


It is time to enjoy the result, but for this we need to run the application. To do this, the tab Run click on Run ‘app’ . We should already be set to the virtual device Android, its installation we discussed in the first article, so just click OK and wait for the launch of Android Virtual Device. Get ready to launch may not be fast.

 Screenshot_2015-12-02-18- 00-00  Screenshot_2015-12-02-18-00-07

You can also test your application on your own device. To activate this setting Developer and debugging via USB. When you connect your smartphone to your computer it will be displayed in the window available for testing devices in the Android Studio.

Congratulations, you have created your first application for Android, and I hope – it runs and runs. Of course, you have not become a developer product that can be sold via Google Play, but still ahead. If you dragged the process, try to start learning to program in Java. Keep in mind that our cycle is not finished and will soon together with you we will write our first game for Android.


No comments:

Post a Comment