How to set up smartphones and PCs. Informational portal

How to write an Android application using Android Studio. What programming language to learn for Android development

XXI Century. The era of digital technologies and the Internet. Reality is becoming more and more virtual. Today, almost every first inhabitant of any developed country does not part with a smartphone. And if some people prefer the fashionable Iphone and the IOS operating system, then the majority use Android devices. After all, they are cheaper and the choice of applications is much richer. And to create such applications, you need specially trained people called programmers. What do you need to know and be able to in order to immerse yourself in Android programming?

Development tools

Development requires special knowledge and tools.

The first thing you need is a work laptop or desktop computer. Only it should not be very ancient. The choice in favor of a laptop is justified by the fact that you can study and practice in any convenient place.

In order to test creations, you need a smartphone with the Android operating system. The system version must be at least the penultimate one. This is important because the speed of development of new gadgets and software is just crazy, every day there are different updates, the developed application should work equally well on both old and new devices. Programming Android applications requires constant monitoring of the latest technology news.

Installing the required software

Before starting development, you should install drivers for your smartphone on your computer. This is if Windows is installed on the computer. The rest of the systems do without special drivers. It is better to search for them on the official website of the device manufacturer. If in the process of programming questions arise (and they will arise constantly), then you need access to the Internet. Development for Android takes place in the "Android Studio" program. It is downloaded from the official site. The program was developed by Google.

What sources to choose?

When studying, there is absolutely no need to read absolutely all sources of information, take all courses and lessons from the World Wide Web and watch all videos. You need to be able to find correct and relevant information. Android programming is like this: what was new a year ago is outdated today. If the training takes place under the guidance of a person, then this teacher should be a master of his craft. A bad programmer will not teach you anything; after the time spent, you will have to relearn again.

Which book should you choose? A book from the Head First series "Programming for Android" has proven itself well. It describes the entire process in an accessible form for a beginner. The authors chose not boring and monotonous, but a humorous manner of presenting the material with a lot of interesting tasks.

Programming language

The main language in which applications are developed is Java. Therefore, you need to know it at least at an initial level in order to make Android programming easy. Without Java knowledge, nothing will come of it. It is one of the most popular programming languages ​​around the world. It is much easier to learn than the C and C ++ languages. Java is strongly typed, and this will instill good coding practices. There is also a book from Head First for learning this language. Anyone can master programming for Android. The main thing is to have motivation.

Motivation and ways to learn

For starters, you can start with 15 minutes a day. If it tightens, then gradually add 5 minutes. At first, there is no need for hours of sitting at the computer. Only professionals can do this. Yes, and desire can be lost.

Programming is more interesting to do not alone. You can find interested persons among friends. If there are none, then there is always the Internet. Social networks and forums will help you find like-minded people. And such a group of programming fans could later turn into a large international corporation.

At first, you can view someone else's code and try to understand it, make some of your own edits. Sources can always be found in the public domain. Then you can come up with an app for a friend or family member and try to implement it. Even a fully functional simple calculator written by hand will delight a beginner. Further, you can complicate the tasks. The most important thing is to practice daily. Theory is good, but you can't become programmers without practice.

There is one good technique for learning: when going through a new topic, you must try to explain it to another person. If he understands, then the goal has been achieved and the topic has been mastered.

There may come a time when you want to quit Android programming. There are always difficulties, but don't be discouraged. There is no need to chase the professionals, the main thing is that the classes are regular, and over time the level will certainly improve, and the difficulties will seem ridiculous. In the end, programming is very interesting and, as an addition, profitable and promising. Indeed, now even for the kettle to function, you need to write a program.

The article describes the main difficulties in creating applications for Android.
The basic concepts of Android programming are covered.
For example, the creation of a Sudoku game from the book Hello, Android - Ed Burnette is described.
Carefully a lot of screenshots.

1. Development difficulties

Android is a unique operating system. An application developer must know its features and nuances in order to get a good result. There are some difficulties to consider when developing (). Let's list them briefly:
1) The application requires twice (or even four) more space to install than the original application size.
2) The speed of working with files on the built-in flash drive drops tenfold with decreasing free space.
3) Each process can use up to 16 MB (sometimes 24 MB) of RAM.

2. Principles of developing productive applications for Android

Requires Android SDK and Eclipse to work. How to install and start everything is written.

To load a project into Eclipse, you should perform the following sequence of actions:
1) Unzip the project to a separate folder in the Eclipse workspace.
2) Select the menu item File-> New-> Android Project.
3) In the New Android Project dialog, select the Create project from existing source option.
4) In the Location field, specify the path to the folder with the project. Click Next.

Program menu

The game menu is described in the res / layout / main.xml file. The interface description can be edited as XML or as a rendered interface. You can switch using the tabs at the bottom of the content display area.

Typically, controls are contained within a container, in our case a LinearLayout. It arranges all the elements in a single column.

Resources

Please note that all text boxes (android: text) take data from resources. For example, android: text = "@ string / main_title" indicates that the text should be searched for in res / values ​​/ string.xml under a node named main_title (Android Sudoku). The background color is also contained in the resources (android: background = "@ color / background") but in the color.xml file (# 3500ffff). An error may occur when opening resource files in the editor. But you can always go to the XML display.

Controls that need to be accessed from code must have an id. The buttons have an id (android: id = "@ + id / continue_button") so that you can attach a click handler to the button. The plus sign indicates that an identifier must be created for the button in the /gen/org.example.sudoku/R.java file (public static final int continue_button = 0x7f0b000b;). This file is generated automatically and it is not recommended to modify it. The file contains the R class through it you can refer to any interface element and other resources.

Create windows

Let's consider creating a window with information about the program. The markup for this window is in the /res/layout/about.xml file. The Activity class is described in the /src/org.example.sudoku/About.java file. Activity is linked to markup in AndroidManifest.xml file. This file can be viewed either through an editor or as XML. On different tabs of the editor, you can select different sections of the file. The Application section contains Activity parameters. Note that the Theme parameter is set to style / Theme.Dialog. This makes the window look more like a modal dialog.

The window with information about the program is invoked from the Sudoku class by pressing the About button. The Sudoku class is written so that it handles the Click event itself (public class Sudoku extends Activity implements OnClickListener). In the public void onClick (View v) method, it is determined which button triggered the event and the corresponding code is executed. To display the About window, the corresponding Intent is called.
case R.id.about_button:
Intent i = new Intent (this, About.class);
startActivity (i);
break;

Event handlers can also be installed on specific controls. For example, in the Keypad class, when the class is created, handlers for individual buttons are set in the setListeners () method.

Simple dialogue

The user needs to be given the opportunity to choose the level of difficulty. This is a small dialog in which you need to choose one of several options. I am very glad that for this you do not need to create a separate Intent, but just use the AlertDialog class.
Let's analyze the process of starting a new game. The user clicks on the New Game button. The click handler is the onClick method of the Sudoku class. Next, the openNewGameDialog method is called, which shows the difficulty selection dialog and starts the game with the selected difficulty level. This dialog is built using the AlertDialog class.

Private void openNewGameDialog () (new AlertDialog.Builder (this) .setTitle (R.string.new_game_title) .setItems (R.array.difficulty, new DialogInterface.OnClickListener () (public void onClick (DialogInterface i) dialoginterface (i);))). show ();)

Note that the contents of the dialog (set of buttons) are built from the array of strings R.array.difficulty. A handler for pressing the buttons of the dialog is immediately assigned, which, according to the number of the pressed button, starts a new game with a given level of difficulty by calling the startGame method.

Graphics

The Game class is responsible for the game logic. Here tasks are loaded, the conditions of winning are checked. The Game class is an Activity, but the interface is not described in XML, but is created by code. The onCreate method creates a View:

PuzzleView = new PuzzleView (this);
setContentView (puzzleView);
puzzleView.requestFocus ();

PazzleView is a View-derived class that draws the game board and handles screen touch events (onTouchEvent method) and key presses (onKeyDown method).

Let's take a look at the drawing process in Android. To draw, you need to overload the onDraw method. The method gets a Canvas object through which drawing is done. To set colors, objects of the Paint class are created. The color is specified in ARGB format. It is better to store color as resources (colors.xml file). Paint is not only a class for storing color information. For example, when you draw text, it contains information about how the text is painted, the font, and the alignment of the text.

Canvas contains a set of methods for drawing graphics (drawRect, drawLine, drawPath, drawText, and others).

To optimize graphics, it is better to refrain from creating objects and unnecessary calculations inside the onDraw method (the considered example of graphics implementation is not optimal).

Music

The MediaPlayer class is used to play music. Music for the game has been added to resources. You just need to copy the files you need to the / res / raw folder (WAV, AAC, MP3, WMA, AMR, OGG, MIDI formats).
First, you need to create an instance of the MediaPlayer class:
mp = MediaPlayer.create (context, resource);
here context is usually a class that initiates the launch of music, resource is an identifier of a resource with music. The start, stop and release methods are used to control playback.

In the game, music is played in the main menu (launched from the Sudoku class) and in gameplay (launched from the Game class). The Music class has been created to control playback. The class contains a static instance of MediaPlayer, which means you don't have to create a separate project for each launch of an audio resource.

The onResume and onPause methods have been redefined in the Sudoku and Game classes, in which the music starts when the Activity starts and stops when it is deactivated.

conclusions

The example that is considered in the article is not too complicated, which allows you to figure it out without much effort. In doing so, it touches on various aspects of Android development.

P.S. Many thanks to the user

The Android operating system every year becomes not only a suitable OS for ordinary users, but also a powerful platform for developers. What can you do: Google always meets developers halfway, providing ample opportunities and powerful tools, flavored with informative documentation.
In addition, one should not lose sight of the fact that the "green robot" is the leader in popularity among mobile operating systems. This suggests that by programming for Android, you will have a wide audience, which can subsequently bring profit. In general, Android is a kind of "oasis" for developers. Therefore, we have prepared for you a special selection of programming languages ​​and development environments for this OS.
Attention, a little instruction for beginners
: Android programming can seem complicated or overly monotonous at first. Hint: Take a look at the links to useful documentation before you get started, and then programming on Android will not be a problem for you.

Java is the primary tool for Android developer

Development environments: Android Studio (IntelliJ IDEA), Eclipse + ADT plugin
Suitable for wide range of tasks
Java is the main language for Android programmers, a must-have for beginners. The main source code for Android is written in this language, so it's easy to see why most people choose this language. Applications written in Java run on Android using the ART virtual machine (or Dalvik in Jelly Bean and earlier versions of Android), a counterpart to the Java virtual machine that has caused Google to have serious litigation with Oracle.

Google currently officially supports a fairly powerful development environment Android Studio, which is built on the basis of Intellij IDEA from JetBrains. Also, do not forget about the very detailed documentation from Google, which understands everything: from match_parent and wrap_content to constructors, constants and main methods of the JavaHttpConnection class - you should definitely read it.

Also, don't forget about Eclipse, a very popular environment for Java programmers. With the official Google ADT plugin, this toolkit is a powerful and lightweight weapon at your fingertips. But the guys from Mountain View have stopped supporting Eclipse since last summer, giving way to the fresh Android Studio. Recommended for use on weak PCs.

Required Documentation:

C ++ is a powerful tool in the hands of a master

Basic development environments: Android Studio (version 1.3 and higher), Visual Studio 2015, QtCreator
Suitable for game engines and resource-intensive applications.
C ++ is a middle-aged, but very powerful programming language that celebrated its 30th anniversary last year. It was invented in 1985 thanks to the efforts of fellow Björn Stroustrup and still occupies the top positions of the most popular programming languages. "Pros" give you complete freedom of action, limiting you only within the framework of reason.


Over the entire existence of Android, many frameworks and development tools for C ++ have been created. I would especially like to highlight the well-known Qt and IDE QtCreator, which allow you to develop cross-platform applications for Windows, Windows Phone, Windows RT, iOS, SailfishOS and Android (once Symbian was also included in this list). Plus, you get a handy Tulip library of containers, algorithms, and templates that draws on the best of Java and Android. Finally, you get a lot of different QT modules for high- and low-level work with the system. Yours truly is coding in a bunch of C ++ and Qt.

Last year, at the Windows: The Next Champter conference, wide attention was paid to the rather popular development environment Visual Studio 2015. One of the main innovations was support for the development of applications for both Windows Phone and Android - Microsoft tried to somehow increase the number of applications for your OS.

It should also be mentioned that the official Android Studio began to support the NDK. With the NDK you can use OpenGL graphics with Android. If you need speed and efficiency - choose NDK! This development method is perfect for game engines that require high performance.

Android development in C or C ++ may seem easier than in Java, but despite the fact that the language offers you complete freedom of action and does not limit you in your steps, it has some specific features that will take a lot of time to learn - not without reason C ++ has been compared to nunchucks (superb weapons that unfortunately require tremendous skill). However, developing Android apps in C and C ++ can be fun.

Required Documentation:

Other languages

Now is the time to talk about other less popular, but also interesting languages ​​and frameworks for them. However, for many reasons, you will not be able to achieve the same success with Java and C ++.

Corona (LUA Script)


Suitable for creating games and simple applications
If for some reason you do not want to learn Java or understand how to build an interface through XML, then you can choose this IDE for yourself. Corona is a fairly lightweight development environment in which you need to write code in a fairly lightweight LUA (Pascal lovers will appreciate it).

This toolkit will help you write simple 2D games, for which there are libraries for 2D = objects, sounds, network and game engine. The games created work with OpenGL, which means high efficiency. Great for beginners, perhaps this is where you can create your first mobile app on Android!


Required Documentation:

Adobe PhoneGap (HTML5, JavaScript, CSS)


Suitable for creating resource-intensive applications
If you are already familiar with HTML, CSS and JavaScript, you can try PhoneGap as an alternative. This IDE will allow you to build full-fledged applications developed in the aforementioned programming and markup languages.

In fact, the ready-made applications from PhoneGap are the simplest WebViews, animated with JavaScript. With the help of various APIs, you can use various device functionality just like in native applications. Interestingly, applications are compiled on the server and then available for use on iOS, Android, Windows Phone, Web OS and BlackBerry OS. With such a wide cross-platform, application development can be significantly accelerated.


Required Documentation:

Fuse (JavaScript and UX)


Suitable for creating both simple and complex applications
When people talk about Android development tools, they often think of Fuse. This tool is one of the most convenient of its kind, and it can present a wide range of possibilities and advantages to the developer.

The main logic of Fuse applications is built on JavaScript - a simple and understandable language with a low threshold of entry. The interface foundation is represented by UX-markup - intuitive for everyone. Well, the "goodies" of the environment will allow you to apply changes right while the application is running on your device or emulator - just like in Android Studio 2.0 and higher. With Fuse, developing Android apps can be fun and easy.

Required Documentation:

Curtain words

Of course, we did not show you all the development tools that exist at the moment. With this article, we wanted to explain to you that becoming an Android developer is not so difficult, although it often requires effort and perseverance. The world of mobile development is open to you, but remember: the first step is always yours.

Google's Android operating system is ideal for developers who want to build apps for mobile phones without having to go through the complex approval processes that Apple has.

This guide aims to provide you with the software and tools you need to help you easily get started developing your own application.

It's not so much how good your programming skills are, as if you can master the Android Software Development Kit (SDK), your apps will turn out just fine. So, check out the materials below to get in the way.

Java Development Kit

The first thing you'll need to get started developing java applications (the foundation of Android applications) is the Java Development Kit (JDK) from Oracle, which can be downloaded from the following link.

You have probably already downloaded and installed the Java Runtime Environment (JRE) in some form, which is required to run applets on your computer. You need to uninstall the version of the JRE that is currently installed on your machine in case it conflicts with the version of the JDK you are downloading. Fortunately, the above version includes the latest and greatest version of the JRE, which will definitely be compatible with the JDK, eliminating the need to reinstall it.

Download and run the installer, make sure ‘Development Tools’, ‘Source Code’ and ‘Public JRE’ are included in the installation in the manual installation window (can be seen below). Click ‘Next’, read the terms of the license agreement if you have enough free time and proceed with the installation.

While most integrated development environment (IDE) applications - we'll talk more about this in the next step - come with their own compiler, I recommend that you embed the Java compiler you just installed on the command line so you can use it on demand.

If you are using Windows, go to System Settings from Control Panel and select Advanced System Settings. Here select ‘Environment Variables’ and find ‘Path’. Add a pre-file in the ‘bin’ directory prior to your Java installation, as shown in the example below.

To check if everything went well, use the ‘java -version’ and ‘javac -version’ commands. You should see something like this:



Installing the IDE

IDEs are often used by seasonal developers and newbies looking to develop applications. For those not in the know, an IDE is an application that helps programmers write code by providing a concise set of tools like debuggers, compilers, and more.

Although there are many IDEs on the internet, we will be using the free Eclipse software here, as Google provides a plugin to integrate it with the Android SDK. You can download the required version of Eclipse.

This may differ from case to case, but when I downloaded the resource, the software was provided as a zip archive that contained an ‘eclipse.exe’ file that could be started without any installation. If your version requires installation, then do it yourself, since there are no special requirements and settings. On first launch, the software will ask you to specify the 'Workbench' where your codes and related files are located. Specify a location convenient for you.

Once complete, the following will be displayed in front of you:

If you would like to familiarize yourself with Eclipse a little before you start, open the Help window and look at the Workbench User Guide. You can also see the Development User Guide here, which will help you master basic Java skills if you are not already familiar with the language.

Downloading the Android SDK

Follow this link and click 'Get the SDK'. On the next page, you will be presented with a link to install the Android SDK on your computer.

As soon as the download of the executable file is completed, start the installation. When you get to the window below, specify the path to the directory where you want to install, or remember the one that is already indicated.

When the installation is complete, open the Android SDK Manager, and then you will see the following window:

Click the button to install all required packages and resources that were not included in the original installation.

Installing the Android Development Tools plugin

As noted above, Google offers a dedicated Android SDK plugin for Eclipse that you can add directly from the IDE.

In Eclipse go to ‘Help’ and select ‘Install New Software’. Click the ‘Add’ button and you will be taken to a window that will allow you to add an online software repository containing the ADT plugin. Give a descriptive name, and enter the following URL in the ‘Location’ block:

  • http://dl-ssl.google.com/android/eclipse

Click ‘OK’. Select the repository you just added and check the ‘Developer Tools’ box.

Click ‘Next’ and go through the steps to install the plugin files. When finished, the following 2 icons should appear in your Eclipse Control Panel:

Now go to ‘Window’ and ‘Preferences’, select the ‘Android’ section and make sure the SDK Location matches the SDK directory you specified earlier. As a result, you should get the following:

You are now the owner of the Android Development Tools plugin.

Configuring the Android emulator

While this helps, you don't really need to have every Android device on hand in order to build apps for them, as Google provides us with a great emulator of its own mobile OS along with the SDK. Before starting development, it is advisable for us to configure the Android Virtual Device (AVD) so that the testing platform is ready in advance.

Now we need to create a new virtual device. This example assumes creating a general device, but there are also resources for specific settings for Android devices. Select 'New' and you will be presented with the following blank window:

  • Name: if you want to test the application on multiple device settings, then you will need to enter something descriptive. On the other hand, a more generic name could also be used.
  • Target: This is the Android version that the emulator will target. In most cases, your option will be the latest version of Android that comes with the SDK being installed. However, if you would like to test on earlier versions (which would be quite wise given so many different versions and models), then use the SDK manager to install additional versions.
  • SD card: Indicator of additional disk space that will be used in the device. By default, the virtual device has 194 megabytes of "internal" memory and an SD card, so you will need to manually specify the required amount of disk space.
  • Skin: You can use this option to set the appearance and configurations of a specific device (HTC One X, for example). But in our case, we are using the default value.
  • Hardware: Since there are significant differences among physical Android devices in terms of hardware, you can use this option to add any hardware that will be used by your application.

When finished, the AVD Manager window should include your newly created device. You can press 'Start' to start this device, just be aware that the first start may take a while.



Your first Android project

Now that you have equipped your computer with all the necessary applications and plugins, you can start developing your code. But first, we need to prepare the project files.

To get started, go to ‘File’, ‘New’, ‘Project’ and expand the Android tab. Select 'Android Application Project' there, and the following window will open in front of you:

You can use the dropdown menus next to each field to select the appropriate value. The main things to consider are the ‘Application Name’, which is responsible for the name of our application during installation, as well as ‘Minimum Required SDK’, with which you specify the earliest Android version that supports your application.

Click ‘Next’ to continue and set the executable icon to be the face of your application. The next menu will ask you to create an ‘Activity’ for your application.

This is an action or view that the user will interact with, so it would be most logical to divide your application into activity in terms of which windows the user will see and what functionality will be available on each of them. So, if you, for example, are creating a simple "Hello World" program, then you only need one active window that represents the text, and all interface settings are extracted from the resource files that the SDK creates.

When you have decided on these windows, click 'Finish'. Eclipse will collect all the files you need for your application together, into which you will write code and / or change settings to specify the parameters of your program.

And that is all! Everything is ready to put together a finished application. Google has full guides on how to develop Android apps (for those with programming experience). Anyone planning to do Java programming should also first read tutorials like the one that Oracle provided us.

How is the Android development process going? Let's highlight a few basics:

  • In Java files, you describe the logic of the program — what you want your application to do.
  • In XML files, you design layouts - appearance.
  • Once the application is written, you need to use a build tool to compile all the files and package them together into an .apk file that can be run on Android devices and / or published on Google Play.
  • All utilities and files that are used to create an Android application are combined into an integrated development environment (IDE). An IDE is a program that you open to edit your code files and compile and run.
  • Eclipse was previously the standard IDE for Android development, but it has now been replaced by the more functional Android Studio, a product of Google.

You will, of course, find deeper processes going on behind the scenes of the above steps. For example, advanced users will want to know the role of the Dalvik virtual machine. At the end of the article, I will list links to useful resources that every Android developer should be familiar with. The first is the official documentation from Google.

  • Download and install Android Studio.
  • We will learn about launching and testing applications on Android devices and emulators.
  • Let's create a simple Android application that displays the "Hello World" text on the screen of a mobile device.

At the end of the article, you can find useful recommendations for novice developers from the company.

Installing Android Studio Development Environment

It's really tempting to start reading the documentation and writing code to find out what the platform is capable of. And we will do it soon! However, to get started with the Android platform, you need to set up a development environment.

It is especially important for beginners in programming for Android to take their time and methodically follow each step. Even if you follow the steps correctly, you may need to troubleshoot a small environment setup issue depending on your system configuration or product version. To do this, use search services. The StackOverflow resource is especially worth highlighting.

It is important not to let any pitfalls interfere with your ultimate goal of learning Android programming. It is known that even professionals sometimes have certain problems with setting up a working environment. In such cases, knowledge of the command line is important. If you'd like to become more familiar with this tool, there is a link to a good introduction below.

Along with practicing the syntax, it is important to educate yourself in a successful programmer mindset that will not accept the file X not found error message as a final verdict. This kind of thinking is easily trained by you in cases when you do not give up and are looking for a solution to the problem that has arisen.

Go to Android Studio developer.android.com/studio/index.html and find a button to download the latest version for your platform.

Click on the download button and you will be asked to read the terms and conditions of use of the software product. After reading carefully (as you always do) and accepting, the download begins. It will probably take a few minutes. After that, you can install Android Studio just like any other program. The download start page provides installation instructions for Mac and Windows.

Now that you've installed Android Studio, let's get it started! Start Android Studio. The program will ask if you want to import your settings. Since you are starting from scratch, just select the second item and continue.

You should see a nice Material Design loading screen.

When the download is complete, you will be taken to the welcome screen.

Even if you just downloaded Android Studio, you may not have the latest version. To avoid problems with versions in the future, click the "Check for updates now" button and, if necessary, follow all instructions to get the latest version. Sometimes Studio will automatically inform you that there is an update using a screen like this:

In this case, always select Update and Restart. Fine! We've successfully completed the development environment setup.

Creating your first Android project

It's time to create your first project. Let's start simple. It is customary for programmers to call the first program "Hello World". Let's follow this tradition and then make a few small changes so that the application uses your name for the greeting. In the end, you can download it to your device and show it to your friends. Android Studio has a little step-by-step tool to help you create your project. Click "New Project" on the start screen:

Fill it in like this. Feel free to replace "example" in the package name with something else to remove the warning at the bottom of the screen. You can also set the project location by specifying any folder on your hard drive

For dropdown SDK versions, see the Description section at the bottom of the dialog box. It explains what each setting is for.

Install the minimum required SDK as shown in the screenshot. This sets the minimum Android version required to run the application. Choosing this value for your own projects is a matter of balancing the SDK capabilities you want and the devices that will be supported.

For more information on API versions and their usage, there is a dedicated Dashboards page on the Android developer site https://developer.android.com/about/dashboards/index.html.

After selecting the version, the screen for selecting the starting template opens. You can create an app that already interacts with the google maps api and displays the map. In our test case, select Empty Activity and click the Next button.

And now you are at the last step of the application creation process. Before clicking Finish, there are a few things to note. This is where you first come across references to the main architectural components of any application.

  • - this is the first, but not the last mention of the word Activity. In the context of Android, an Activity is usually seen as a "screen" in your application. This item is very flexible. When Android Studio creates the MainActivity class, it inherits from the Activity class from the Android SDK. Those familiar with object-oriented programming understand this concept, but for beginners, this basically means that your MainActivity will be a custom version of an Activity.

  • Layout Name- the layout of what will be shown to the user is defined in a special Android XML form. You will soon learn how to read and edit these files.

Click Finish. It will take some time to create and load the project. After a while, Android Studio will complete the build of your project. Of course, the project is still empty, but it has everything you need to run on an Android device or emulator.

After loading the project, you view the XML layout file. Before moving on to Android programming, let's talk about how we can get this application running. It's time to say "Hello world!"

Launching the application on the emulator

Now it's time to say a few words about the emulator. Android Studio comes with software capable of emulating an Android device for running applications, browsing websites, debugging, and more.

This feature is provided by Android Virtual Device (AVD) Manager. Optionally, you can configure multiple emulators, set the screen size and platform version for each new emulator. This functionality is very useful as it eliminates the need for developers to buy multiple devices to test programs.

Click on the Run button in the form of a green arrow.

You will have to wait a while for the emulator to load and as soon as it is ready you will see something like this:

My congratulations! You've made your first Android app!

And so ... Why and how did it work?

Getting started with making changes and adding cool features requires a working knowledge of what's going on behind the scenes. Take a look at the files and folders section of the Android Studio project on the left side of the screen. You may need to click the small tab on the edge (see below) if the project explorer is not currently displayed.

Review the folder structure for a few minutes and double-click on the files to see their contents in the main window. If this all looks cryptic, don't worry!

Android project structure: Team

Every good team is made up of people who fulfill their assigned roles. Do you want to get the job done right? You need the right team. There are several key elements in Android projects, and each of them must play a specific role:

Java: Professional

This is the part of your code that is responsible for the logic of your application. Your code will be in the src \ main \ java directory in the main project folder. For learning Java, consider Bruce Eckel's book Philosophy of Java;

Resources: Artist

It's not enough just to make an Android app, it also needs to be stylish. Your app will never stand out if it doesn't have clear icons and images, well-thought-out layouts, and maybe even fluid animations.

During initialization, the folder contains the following folders:

  • drawable, which stores icons. Now there is only a standard application icon.
  • layout with XML files that represent screen designs.
  • menu with XML files of lists of elements that will be displayed in the action panel.
  • values ​​with XML files containing sizes, colors, string constants, and styles.

AndroidManifest.xml: Boss

This XML file informs your system about the hardware and software requirements of the application and contains its version name and icon. The manifest also contains information about all Activities in the application. Do you need work done by your application? Talk to your boss first.

Alteration

Go to res / values ​​/ strings.xml and double click on the file. When you open the file, you will see two string resources in XML.

These resources are used in different places, but it is very convenient to have all the text used in your application in one file. If you need to translate it, or if your marketing colleague asks you to remove any redundant links, it's easy to make all the changes here.

Change the hello_world line that the application displays on the screen. Change its content to something more personal, such as using your own name. You will end up with something like:

Matt is learning Android!

Click Run. The application should restart and you will see a personal message:

We congratulate you - you completed your first project and learned how to edit source code. The first step in Android programming has been made. We wish you good luck on this challenging but incredibly interesting journey! If you need professional development of an Android application, contact Infoshell specialists.

Top related articles