How to learn to write android applications yourself. Applications for application development: how to make an application for iOS and Android yourself

Learning a new language and development environment is the minimum that is required of you if you want to write your first mobile application. It will take at least a couple of weeks to sketch out a basic todo list for Android or iOS without copying the example from the book. But you can not master Objective-C or Java and still quickly develop applications for smartphones if you use technologies such as PhoneGap.

If you have carefully studied the innovations that await us in Windows 8, you may have noticed that it will be possible to develop applications in HTML5 under it. The idea, in fact, is not new - technologies that implement the same approach for mobile platforms are developing by leaps and bounds. One of these frameworks, which allows you to develop applications for smartphones using a bunch of familiar HTML, JavaScript and CSS!, is PhoneGap. An application written with its help is suitable for all popular platforms: iOS, Android, Windows Phone, Blackberry, WebOS, Symbian and Bada. You will not need to learn the specifics of programming for each platform (for example, Objective-C in the case of iOS), or deal with various APIs and development environments. All you need to create a cross-platform mobile application is knowledge of HTML5 and a special PhoneGap API. In this case, the output will not be a stupid HTML page “framed” in the application interface, no! The framework's API allows you to use almost all phone capabilities that are used when developing using native tools: access to the accelerometer, compass, camera (video recording and photography), contact list, file system, notification system (standard notifications on the phone), storage, etc. . Finally, such an application can seamlessly access any cross-domain address. You can recreate native controls using frameworks like jQuery Mobile or Sencha, and the final program will look like it was written in a native language (or almost so) on a mobile phone. It is best to illustrate the above in practice, that is, write an application, so I suggest you start practicing right away. Keep track of the time - it will take hardly more than half an hour to do everything.

What will we create

Let’s take iOS as the target platform - yes, yes, the money is in the AppStore, and for now it’s best to monetize your developments there :). But let me make it clear right away: the same thing, without changes, can be done, say, for Android. I thought for a long time about which example to consider, since I didn’t want to write another tool to keep track of the to-do list. So I decided to create an application called “Geographic Reminder,” a navigation program whose purpose can be described in one phrase: “Let me know when I’m here again.” The AppStore has many utilities that allow you to “remember” the place where the user parked the car. It's almost the same thing, just a little simpler. You can point to a point on a city map, set a certain radius for it, and program a message. The next time you fall within the circle with the specified radius, the application will notify you and the point will be deleted. We will proceed according to this plan: first we will create a simple web application, test it in the browser, and then transfer it to the iOS platform using PhoneGap. It is very important to prototype and test the bulk of the code in a browser on a computer, since debugging an application on a phone is much more difficult. We will use the jQuery JS framework with jQuery Mobile (jquerymobile.com) as the framework, and Google Maps v3 as the map engine. The application will consist of two pages: a map and a list of points.

  • A marker of your current position is placed on the map. By clicking on the map, a point is created to which a message is attached (like “car nearby”). A point can be deleted by clicking on it. To move a person's marker on the map, a geonavigation API is used.
  • On the page with a list of points there should be an additional “Delete all points” button, and next to each point there should be a “Delete this point” button. If you click on an element in the list, the corresponding point will be displayed on the map. We will save the user settings and the list of points in localStorage.

UI frameworks

jQuery Mobile is, of course, not the only framework for creating a mobile interface. The PhoneGap website has a huge list of libraries and frameworks that you can use (phonegap.com/tools): Sencha Touch, Impact, Dojo Mobile, Zepto.js, etc.

Application framework

I’ll immediately explain why we will use jQuery Mobile. This JS library provides us with ready-made mobile application interface elements (as close as possible to native ones) for a variety of platforms. We need the output to be a mobile application, and not a page from a browser! So download the latest version of JQuery Mobile (jquerymobile.com/download) and transfer the first application files that we need to the working folder:

  • images/ (move here all the images from the jq-mobile archive folder of the same name);
  • index.css;
  • index.html;
  • index.js;
  • jquery.js;
  • jquery.mobile.min.css;
  • jquery.mobile.min.js.

It is necessary to make the resources mostly local so that the user does not waste mobile Internet in the future. Now we create the page framework in the index.html file. The code below describes the top of the page with a map, the inscription “Geographic Reminder” and the “Points” button.

Map page

Georemembrance

Points

The page attribute data-dom-cache="true" is necessary to ensure that it is not unloaded from memory. The Points button uses data-transition="pop" so that the Points List page opens with a Pop-in effect. You can read more about how jQuery Mobile pages are structured in a good manual (bit.ly/vtXX3M). By analogy, we create a page with a list of points:

Point list page

delete everything

Points

Map

For the “Map” button, we will also write data-transition="pop", but we will add the data-direction="reverse" attribute so that the “Map” page opens with the “Fade” effect. We will write the same attributes in the point template. That's it, our frame is ready.

Creating an application

Now we need to display the map, for which we will use the standard Google Maps API, which is used by millions of different sites:

Var latLng = new gm.LatLng(this.options.lat, this.options.lng); this.map = new gm.Map(element, ( zoom: this.options.zoom, // Select the initial zoom center: latLng, // Set the initial center mapTypeId: gm.MapTypeId.ROADMAP, // Normal map disableDoubleClickZoom: true, // Disable autozoom by tap/double-click disableDefaultUI: true // Disable all interface elements ));

Here Gm is a variable referencing the Google Maps object. I commented out the initialization parameters well in the code. The next step is to draw a man marker on the map:

This.person = new gm.Marker(( map: this.map, icon: new gm.MarkerImage(PERSON_SPRITE_URL, new gm.Size(48, 48)) ));

The address of the person sprite from Google panoramas is used as PERSON_SPRITE_URL. Its static address is maps.gstatic.com/mapfiles/cb/mod_cb_scout/cb_scout_sprite_api_003.png . The user will add points by clicking on the map, so to draw them we will listen to the click event:

Gm.event.addListener(this.map, "click", function (event) ( self.requestMessage(function (err, message) ( // Method that returns the text entered by the user if (err) return; // Method adds a dot to the list of active ones and // draws it on the map self.addPoint(event.latLng, self.options.radius, message); self.updatePointsList(); // Redraw the list of points )), false);

I provide most of the code - look for the rest on the disk. Next we need to teach the application to move the user icon on the map. In the prototype, we use the Geolocation API (the one that is also used in desktop browsers):

If (navigator.geolocation) ( // Check if the browser supports geolocation function gpsSuccess(pos) ( var lat, lng; if (pos.coords) ( lat = pos.coords.latitude; lng = pos.coords.longitude; ) else ( lat = pos.latitude; lng = pos.longitude; ) self.movePerson(new gm.LatLng(lat, lng)); // Move the user icon ) // Every three seconds we request the current // position of the user window.setInterval (function () ( // Request the current position navigator.geolocation.getCurrentPosition(gpsSuccess, $.noop, ( enableHighAccuracy: true, maximumAge: 300000 )); , 3000);

The movePerson method uses a simple getPointsInBounds() procedure to check if the user is at any active point. Last question - where to store the list of points? HTML5 introduced the ability to use localStorage, so let's not neglect it (I'll leave you to figure out these parts of the code yourself, which I've commented out well). So, the application running in the browser is ready!

Launching a web application

As I said before, debugging mostly needs to be done on the computer. The most suitable browser for testing web applications on a computer is Safari or Chrome. After debugging in these browsers, you can be sure that your application will not work in a mobile phone browser. Both of these browsers are compatible with most mobile web browsers because they are built on the WebKit engine just like them. After eliminating all the bugs, you can proceed to launching the mobile web application directly on your phone. To do this, configure your web server (even Denwer or XAMPP) so that it serves the created page, and open it in your mobile phone browser. The application should look something like the one shown in the figure. It is important to understand here that the future mobile application compiled for the mobile platform using PhoneGap will look almost identical, except that the browser navigation bar will not be displayed on the screen. If all is well, you can start creating a full-fledged iOS application from the page. Please note that we haven’t even touched PhoneGap and the IDE for mobile development up to this point.

Preparation

In order to build an application for iOS, you need a computer with the Mac OS 10.6+ operating system (or a virtual machine on Mac OS 10.6), as well as the Xcode development environment with the iOS SDK installed. If you do not have the SDK installed, you will have to download a disk image from the Apple website that includes Xcode and the iOS SDK (developer.apple.com/devcenter/ios/index.action). Keep in mind that the image weighs about 4 GB. In addition, you will need to register on the Apple website as a developer (if you are not going to publish your application in the AppStore, then this requirement can be bypassed). Using this set, you can develop applications in the native iOS language Objective-C. But we decided to take a workaround and use PhoneGap, so we still need to install the PhoneGap iOS package. Just download the archive from the offsite (https://github.com/callback/phonegap/zipball/1.2.0), unpack it and run the installer in the iOS folder. When the installation is complete, the PhoneGap icon should appear in the Xcode projects menu. After launch, you will have to fill out several forms, but very soon you will see the IDE workspace with your first application. To check if everything is working, click the Run button - the iPhone/iPad emulator with the PhoneGap template application should start. The assembled program will generate an error saying that index.html was not found - this is normal. Open the folder in which you saved the primary project files and find the www subfolder in it. Drag it into the editor, click on the application icon in the list on the left and in the window that appears, select “Create folder references for any added folders”. If you run the program again, everything should work. Now we can copy all the files of our prototype to the www folder. It's time to tweak our prototype to work on a smartphone using PhoneGap processing.

Prototype transfer

First of all, you need to include phonegap-1.2.0.js in your index file. PhoneGap allows you to limit the list of hosts available for visiting. I suggest setting up such a “white list” right away. In the project menu, open Supporting Files/PhoneGap.plist, find the ExternalHosts item and add to it the following hosts that our application will access (these are Google Maps servers): *.gstatic.com, *.googleapis.com, maps.google. com. If you do not specify them, the program will display a warning in the console and the map will not be displayed. To initialize the web version of our application, we used the DOMReady event or the jQuery helper: $(document).ready(). PhoneGap generates a deviceready event, which indicates that the mobile device is ready. I suggest using this:

Document.addEventListener("deviceready", function () ( new Notificator($("#map-canvas")); // If the user does not have Internet, // notify him about it if (navigator.network.connection.type = == Connection.NONE) ( navigator.notification.alert("No Internet connection", $.noop, TITLE); ) ), false);
Let's prevent scrolling: document.addEventListener("touchmove", function (event) ( event.preventDefault(); ), false);

Then we will replace all alert and confirm calls with the native ones that PhoneGap provides us with:

Navigator.notification.confirm("Remove point?", function (button_id) ( if (button_id === 1) ( // OK button pressed self.removePoint(point); ) ), TITLE);

The last thing we need to change is the block of code that moves the user icon around the map. Our current code also works, but it works less optimally (it moves the icon even if the coordinates have not changed) and does not provide as rich data as the PhoneGap counterpart:

Navigator.geolocation.watchPosition(function (position) ( self.movePerson(new gm.LatLng(position.coords.latitude, position.coords.longitude)); ), function (error) ( navigator.notification.alert("code: " + error.code + "\nmessage: " + error.message, $.noop, TITLE); ), ( frequency: 3000 ));

This code is more elegant - it only generates an event when the coordinates have changed. Click the Run button and make sure that the application we just created works perfectly in the iOS device simulator! It's time to start launching on a real device.

Launch on device

Connect your iPhone, iPod or iPad to a computer running Xcode. The program will detect a new device and ask permission to use it for development. There is no point in refusing her :). Let me repeat once again: in order to run a written application on iOS, you must be an authorized iOS developer (in other words, be subscribed to the iOS Developer Program). This will only bother you if you are developing applications for Apple products; with other platforms (Android, Windows Phone) everything is much simpler. Those studying at a university have a chance to gain access to the program for free thanks to some benefits. Everyone else must pay $99 per year to participate in the program. Apple issues a certificate with which you can sign your code. The signed application is allowed to be launched on iOS and distributed in the App Store. If you are not a student, and you still feel sorry for $99 for innocent experiments, then there is another way - to deceive the system. You can create a self-signed certificate for code verification and run the mobile program on a jailbroken iOS device (I won’t dwell on this, because everything is described in as much detail as possible in this article: bit.ly/tD6xAf). One way or another, you will soon see a working application on the screen of your mobile phone. Stop the stopwatch. How long did it take you?

Other platforms

Besides PhoneGap, there are other platforms that allow you to create mobile applications without using native languages. Let's list the coolest players.

Appcelerator Titanium (www.appcelerator.com).

Titanium can build applications primarily for Android and iPhone, but it also claims to support BlackBerry. In addition to the framework itself, the project provides a set of native widgets and IDE. You can develop applications on Titanium for free, but you will have to pay for support and additional modules (from $49 per month). The price of some third-party modules reaches $120 per year. The developers of Appcelerator Titanium claim that more than 25 thousand applications have been written based on their framework. The project's source code is distributed under the Apache 2 license.

Corona SDK (www.anscamobile.com/corona).

This technology supports the main platforms - iOS and Android. The framework is aimed mainly at game development. Of course, the developers claim high-quality optimization on OpenGL. The platform does not have a free version, and the price is quite steep: $199 per year for a license for one platform and $349 per year for iOS and Android. Corona offers its own IDE and device emulators. Corona applications are written in a language similar to JavaScript.

Conclusion

We created a simple mobile web application and ported it to the iOS platform using PhoneGap in a few simple steps. We didn't write a single line of Objective-C code, but we got a program of decent quality, spending a minimum of time porting and learning the PhoneGap API. If you prefer another platform, for example Android or Windows Mobile 7, then you can just as easily, without any changes for these platforms, build our application (for each of them there is a good introductory manual and video tutorial: phonegap.com/start) . To verify the platform’s viability, you can look at ready-made applications on PhoneGap, which the technology developers have collected in a special gallery (phonegap.com/apps). In fact, PhoneGap is an ideal platform for creating at least a prototype of a future application. Its main advantages are speed and minimal costs, which are actively used by startups that are limited in resources in all respects. If the application fails, and for some reason you are no longer satisfied with the HTML+JS internals, you can always port the application to a native language. I can’t help but say that PhoneGap was originally developed by Nitobi as an open source project (the repository is located on GitHub: github.com/phonegap). The source code will continue to remain open, although Adobe bought Nitobi last October. Need I say what prospects the project has with the support of such a giant?

The Android operating system is one of the most popular mobile platforms in the world today. Almost every owner of an Android smartphone would like to get a unique application that is suitable for him in a particular case, but it is not always possible to find such an application. In this article we will talk to you about how to make an Android application yourself using free methods.

Due to the rapid development of the Android platform, some functions of the described programs may change, so to clarify any details, write in the comments. Last edition - 01/20/2018.

Naturally, progress does not stand still and with the development of the Android OS there are more and more opportunities for creating various kinds of applications that are suitable for it. And if recently, only a specialist who studied this at the institute could create it, now he can do it any owner of a phone or tablet Android online.

Users can create their own application in order to please themselves with a unique program. Or they can do it in order to earn some money. Today the Internet provides all the opportunities for this.

The tools described below will allow you to create your own application in several stages.

Some of the presented programs allow you not only to do, but also monetize immediately his. Also, any of the created applications can be placed on the Google Play system.

Four ways to make an Android app yourself

Below you will find four “tools” that will allow you to create such an application quickly and without special knowledge. Such programs are reminiscent of construction kits that allow you to create everything you need block by block, a good analogy with assembling the familiar LEGO construction set.

All programs presented here were selected according to the following criteria:

  • Convenient use. Naturally, these offers will not be used by trained specialists, but by ordinary users, like you and me. That is why the application should be very convenient, functional, and easy to use.
  • Intuitively simple interface. Logically speaking, this point seems to follow from the previous one, which means the program should not only be convenient, but also intuitive.
  • Great functionality. The wide variety of ways to create an application is a definite plus. Although all the programs presented, on average, have the same functions, with the exception of some minor details.

Below we will take a look at a selection of tools that will help you create your very first application.

App Builder - a simple tool for creating applications

This option is a good way to create your own applications quickly. Without a doubt, the good news is that you can use it without investing a penny, which means for free. Although there are also disadvantages here, at least in the fact that it is entirely in English (after the update in December 2017, Russian was added).

Program features

  • There is a huge selection of templates for creating an application. If you have some simple application in mind, then this program will easily help you select a template;
  • After creating the application, you can monitor its statistics;
  • If you create an app and it passes review, it can be easily and fairly easily listed on the Google Play Store.

AppsGeyser - a site for creating high-quality Android applications on your own

Official website - https://www.appsgeyser.com

This tool is better than the previous one, because there are many more opportunities for creating your own application. The site allows you to create your own program in just a few minutes. This editor is the simplest of all that we have encountered. The list of applications that it will help you make is very large, starting from a regular browser and ending with your own messenger.

Benefits of AppsGeyser

  • The application is written quite quickly, literally in a couple of clicks;
  • It allows you to create simple games for Android, because you must admit that not every tool today can do this;
  • Once the application is ready, it can be easily placed in the Google Play store;
  • In addition, you can monetize your program directly through the AppsGeyser service. This is a useful function, because by showing your imagination, you can also make money from it;
  • Create, edit, publish an application online in your personal account (so that the results are saved).

IbuildApp - a powerful engine for developing your own projects

This tool deserves a really thorough look. As we discussed above, you don't need to know a programming language to create Android apps. The development platform is so simple that creating your own application will be very simple. The process will only take a few minutes, but the result will be obvious.

The IbuildApp website has both paid plans (development of an individual application, with further development) and free templates, of which there are a lot.

Russian official website - https://russia.ibuildapp.com

Let's see what it can do:

  • A huge archive of topics on a variety of topics: it could be restaurants, cafes, sports activities, and many other topics that allow you to choose anything you want. All you need to do is select something specific, and then edit it to suit your needs;
  • It also has built-in ways to promote the created application. The program not only helps you quickly create an application, but also promotes it. In other cases, this process takes a very long time;
  • In addition, you will be able to connect the application to the advertising network, which means you will earn money from it.

AppsMakerstore - platform for creating simple programs

Official website - https://appsmakerstore.com

The fourth cool platform that is designed for creating Android applications. Probably one of the most important advantages is that using the AppsMakerStore website you can create programs that will be multi-platform (for example, on Android, iOS and Windows Phone)

Let's look at the advantages of the platform:

  • Work with the designer takes place online;
  • Possibility of free registration;
  • Writing applications using ready-made layouts, while a huge selection of templates on the topic is provided to each user.

Video instructions for creating an application using APK Creator


That's all, we hope that you found what you were looking for and were satisfied with our selection. This set of tools will become something special for a novice programmer and will allow you to understand the intricacies of creating simple applications for free.

Programming is one of those areas where everyone can feel like a creator. Usually it refers to the development of applications for personal computers, units of production equipment, or simply for electronic homemade products. But with the spread of touchscreen mobile devices, programming for Android, iOS or another system shell of a similar type is becoming more and more popular. Well, I must admit, this is a promising occupation. Therefore, within the framework of the article, we will consider running Android from scratch. What features are there? What language is used?

Creating programs

Before writing programs yourself, you need to study all the components necessary for this:

  1. Language.
  2. Select your development environment. We will also dwell on the language in detail, as well as on the software products where applications will be created. But first, let's talk a little about development environments. Conventionally, they can be divided into three components:
  • graphic;
  • ordinary;
  • online.

Regarding the creation of programs, it should be noted that now it is difficult to put forward an idea that has not already been worked out before. Therefore, if a problem arises or simply in the case of a lack of knowledge, it is necessary to correctly formulate the misunderstanding that has arisen and turn to more experienced programmers. They will be able to help you create programs with constructive advice.

What language are programs written in?

Java is used for these purposes. It should be noted that this is a rather complex programming language. But you don’t need to know it completely to create your own applications. Basic knowledge and skills in working with reference information will be enough to get answers to your questions. In addition, there are certain presets, using which you can take some steps to create an application without significant problems. Then programming for Android becomes a pleasure.

Choosing a regular development environment

Eclipse and the Android SDK are seen as the biggest players. They are both free. Overall, it should be noted that these development environments are serious competitors, and each of them has a number of strengths and weaknesses. Each of them is worth studying. Separately, let us just dwell a little on one aspect of the Android SDK - the emulator. It is a program that pretends to be a phone or tablet that runs on Android. The emulator runs smoothly on a regular computer and looks like a standard mobile device on the desktop. There is only one peculiarity - it is controlled using the mouse and keyboard, and not with your finger. In the emulator, you can check the functionality of the application for various screen extensions, as well as on different versions of the Android mobile operating system. Therefore, no matter how strange it may sound to you, when developing applications aimed at Android, it is not at all necessary to have a phone.

What do you need to develop your application?

Graphical development environments

This option is suitable for those who have no idea about programming in general, but want to get their application here and now. First, you should familiarize yourself with the description and capabilities of graphical development environments. Thus, some can place only the simplest elements and attach minimal functionality to them. It is better not to use such resources, since with their help it will be difficult to understand the logic of work and create a developed final product. It is advisable to make a selection according to the following parameters:

  1. Availability of an intuitive interface.
  2. Using clear operating logic.
  3. Ability to create elements in graphical and code modes.
  4. Availability of documentation for working with the development environment and a support forum.

Online development environment

They can provide quite a wide range of functionality in a simple access point - the Internet. “Online development environment” probably says it all. Although it should be clarified that under Android it is still not an easy task. So, the most difficult will be to implement shooters and applications of similar complexity. But programs with text formatting and data transfer are easy.

Conclusion

We hope there are no more questions about the first steps of preparing to create your own programs. If you decide to get serious about programming, then you can use special literature. For example, the book “Programming for Android” by Hardy Brian. Of course, this is not the only good work, but you have to start somewhere. By reading this manual, you can begin the path to success.

The Android operating system is installed on 66.71% of all mobile devices in the world. So it is not surprising that many beginning IT specialists want to realize their ambitions on this platform.

Most recently on GeekBrains we touched on mobile platforms, but this time we’ll take a closer look at Android. Here are 10 languages ​​that will allow you to create a mobile application of any type and complexity:

Java

It wouldn't be much of an exaggeration to call Java the official language of Android. In any case, almost all educational documentation, all online courses are based on this. It is also the most popular language according to TIOBE, the second in the number of sources on GitHub, and in general a big beautiful language. This is why learning Java should be a top priority for any Android developer. Even though it won’t be easy (after all, the language is 22 years old, and ease has never been its strong point), even though theoretically you can get by with more modern languages, remember - it is impossible to achieve significant success on Android without absolutely understanding Java, not to mention specific source codes.

C#

With all the endless skepticism directed towards Microsoft products, it is worth admitting that C# does not deserve it. This is a wonderful language that has absorbed all the best from Java, while taking into account and correcting many of the shortcomings.

When it comes to Android application development, you have one of the most functional environments at your disposal: Visual and Xamarin Studio. And knowing C# will be a nice bonus for you when you get to using Unity 3D. With this set the possibilities are endless.

Python

Just because Android doesn't support using Python to build native apps doesn't mean it's not possible. Fans of this snake language have developed many tools that allow you to compile Python code into the required state.

The most popular framework is Kivy, which can easily help you create an application for the Play Market in pure Python. And if not, then kind developers will help in the chat. If you haven't mastered it yet, we recommend taking it.

Kotlin

In the text about, I already tried to explain why Kotlin itself is an excellent language, and in conjunction with Java it is even better. Indeed, officially released only a year ago, Kotlin is quickly winning the hearts of developers around the world with its almost complete absence of flaws.

With its help (more precisely, with the help of the native IntelliJ IDEA environment), you will not feel any problems in developing native applications for Android. At the same time, the demand for Kotlin specialists is still low, which means that by gaining experience working with it, you risk gaining a competitive advantage in the future.

Web languages

Standard web worker language set: HTML, CSS and JavaScript. Without knowing these 3 languages, you will reduce yourself to developing applications with a rather narrow focus. Even if you don’t want to touch the web directly in your future work, it’s unlikely that you can avoid hybrid applications.

You can work with HTML, CSS and JavaScript using the PhoneGap Build environment or, in a more specialized case, Adobe Cordova. They will not require much knowledge from you, but will provide results. Or from the last one, React Native from Facebook is the next level of ease of interaction, but little experience and documentation has accumulated. In general, choose, fortunately there is plenty to choose from.

Lua

A language that is older than Java, much less popular, but still in demand. It has a number of advantages, such as dynamic typing and relatively simple syntax, but it has survived to this day thanks to its involvement in games. It was the convenience of creating a software layer between the engine and the shell that opened the door for Lua to the world of pocket gadgets.

Corona SDK is an environment for developing mobile cross-platform applications, mainly games, where the main tool is Lua. Since 2015, it has been distributed free of charge, designed for beginner developers, plus you can find a lot of useful information in both the English and Russian segments of the Internet.

C/C++

Google actually provides developers with two development environments: the SDK, which is designed to work with Java, and the NDK, where the native languages ​​are C/C++. Yes, of course, you won’t write an entire application using only these languages, but with their help you can create a library, which you can later connect to the main body of the program using Java.

Even though the vast majority of developers don't care about the NDK, by using this tool you will get better results in terms of performance and internal resource utilization. And this is exactly what on Android distinguishes a good app idea from a good implementation.

What languages ​​do you write in?

Please note that the studio is constantly being updated, so the appearance of windows and other details may differ from this example. Most of the lessons on the site now use version 2.3. On October 25, 2017, version 3.0 was released, in which a lot has changed. In this article I tried to replace all the pictures with the new version.

Java is used as the programming language for Android. XML is used to create the user interface.

Here we should make a small digression. Android Studio 3.0 adds full support for the new Kotlin language, developed by Kotans. Google has announced its plans to make the new "cat" language the main one. But you must understand that a huge number of examples have been written in Java over the previous years. If you are new to programming, then it is better to completely focus on Java during the first period of training; it will be easier for you to find answers to questions. Kotlin will not escape you, it will be easier to switch to it later, but the reverse process will be more difficult. When you get a little familiar with Java, you can simultaneously study examples in Kotlin. Google is now actively rewriting the documentation for Kotlin, but the complete transition is still far away, even less than 50%. A little later I will also do lessons using Kotlin, but this will not be soon.

According to a tradition established in the last century, every programmer had to write “Hello World!” (Hello World!) as the first program. Times are changing, and the Hello World! is already built into the Android development environment for compatibility purposes, and modern programmers must write a program Hello Kitty!(Hi kitty!). Agree that greeting a kitten makes more common sense than saying hello to any other world.

Therefore, we will divide the problem into two parts. First, let's run the finished program without writing any code to make sure that all the tools are installed correctly and we can create and debug programs. And then we’ll write our first program.

Creating a new project

Launch Studio and select File | New | New Project.... A wizard dialog box will appear.

Field Application name- a friendly name for the application that will be displayed in the application title. By default you may already have My Application. Let's replace it with . Basically you could write here and Hello world!, but Android has a wonderful ability to output the desired strings on phones with different languages. Let's say that an American's phone will have an inscription in English, and a Russian's will have an inscription in Russian. Therefore, the initial settings always use English variants, and prepare localized strings later. It is necessary to immediately develop the habit of correct code.

Field Company Domain serves to indicate your site. By default, your name as the computer user may appear there. If you have a website, you can enter its address, or come up with some name. The entered name is remembered and will be automatically substituted in the next new projects. Savings, however.

Third field Project location allows you to select a disk location for the created project. You can create a separate folder on your disk for your projects and store your programs in it. The studio remembers the last folder and will automatically suggest saving in it. If necessary, you can set a different location for an individual project using the three-dot button.

Field Package name generates a special Java package based on your name from the previous field. Java uses an inverted version for naming packages, so it goes first ru, and then the name of the site. The package serves to uniquely identify your application when you distribute it. If a hundred people write a hundred applications with the name "Cat", then it will be unclear where the application written by the developer Vasily Kotov is. And the application with the package name ru.vaskakotov.cat easier to find. Please note that Google uses the package in its documentation com.example for demonstration purposes. If you simply copy examples from the documentation and try to post them in this form on Google Play, then nothing will work - this name is reserved and prohibited for use in the application store. Button Edit allows you to edit the prepared version. For example, you are writing a custom application and you need to use the package name approved by the customer, and not your default.

Below are two options for writing programs in C++ and Kotlin. We are not considering these options yet. When you write in Kotlin, check the appropriate box. However, you can convert the project from Java to Kotlin and later using studio tools.

Click on the button Next and move on to the next window. Here we select the types of devices for which we will develop our application. In most cases, we will write for smartphones and tablets, so we leave the checkbox next to the first item. You can also write apps for Android TV, Android Wear, Android Auto and Android Things.

In addition to selecting the type of device, you must select the minimum version of the system under which the application will work. Choose your option. At the moment, Google supports versions starting with API 7, releasing special compatibility libraries for older devices. But you can choose a more modern option. I have a phone with a minimum version of Android 4.4, so I'm setting this option.

java

Folder java contains three subfolders - working and for tests. The working folder has the name of your package and contains the class files. Now there is one class MainActivity. You can leave the test folders alone. If you know how packages work in Java, you can create new folders and subfolders.

res

Folder res contains resource files divided into separate subfolders.

  • drawable- graphic resources are stored in these folders - pictures and xml files describing colors and shapes.
  • layout- this folder contains xml files that describe the appearance of forms and various form elements. After creating the project there is already a file there activity_main.xml, which is responsible for the appearance of the main application window.
  • mipmap- application icons for different screen resolutions are stored here
  • values- string resources, color resources, themes, styles and dimensions that we can use in our project are located here. Here you can see the files colors.xml, strings.xml, styles.xml. In old projects there was also a file dimensions.xml, it has now been abandoned

Over time, you will be able to navigate these folders freely, as long as you don’t bother yourself.

Working with the project - Hello, World!

As already mentioned, the program Hello, World! is already built into any new project, so you don't even need to write anything. You just need to launch the project and get a ready-made program!

To study you need to open two files - MainActivity(most likely it is already open) and activity_main.xml (res/layout) in the central part of the Studio. If the files are not open, then open them yourself by double-clicking to edit (or view). In this way you can open any file you need.

Let’s not study the code for now, but just click on the green triangle Run(Shift+F10) on the toolbar at the top of the studio to launch the application.

If you haven't configured the emulator, it means you haven't read the previous tutorial. Set up the emulator first and run the project again. Or connect a real device.

If everything was done correctly, your program will load in the emulator or on the device. Congratulations!

So, if the program has started, you will see an application window with the inscription. The title of the program will also be . All these lines can be found in the file res/values/strings.xml and edit if desired.

Now let's look at the code. Let's study first activity_main.xml.

You can watch it in two modes - Design And Text.

Open in mode Text.

This is a new template code that was released in Android Studio 2.3 in March 2017. Previously, a different code was used with RelativeLayout(and even earlier, another code with LinearLayout). If you come across old examples, the studio has a context menu that will help you convert the old code into new one.

A little about XML code. There is a special container ConstraintLayout, which contains the component TextView, intended for text output.

Now let's look at the Java code ( MainActivity.java)

Package ru.alexanderklimov.helloworld; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity ( @Override protected void onCreate(Bundle savedInstanceState) ( super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ) )

You have a class file open in front of you, where the class name is MainActivity matches the file name with the extension java(this is a rule set by the Java language). The first line contains the name of the package - we specified it when creating the project ( Package Name). Next are the lines for importing the necessary classes for the project. To save space, they are collapsed into one group. Unfold it. If one day you see that the class names are grayed out, then they are not used in the project (hint Unused import statement) and you can safely delete the extra lines. They can also be deleted automatically (configurable).

Next comes the declaration of the class itself, which is inherited ( extends) from an abstract class Activity. This is the base class for all application screens. It is possible that you will have AppCompatActivity, if when creating the project you left support for old devices (checkbox Backwards Compatibilty (App Compat)). Old versions did not have the goodies that appeared after Android 4, so a special compatibility library was created for them, which allows you to use new items from new versions of Android in old programs. Class AppCompatActivity This is exactly what the compatibility library refers to. Consider her a poor relative of the base Activity. It has all the necessary methods and helper classes, but the names may vary slightly. And you can't mix names. If you are using a class from the compatibility library, then take the appropriate methods.

At different stages, different activity class names were used, which you may encounter in older projects. For example, it was first used FragmentActivity, then ActionBarActivity, and on April 22, 2015, a new version of the compatibility library was released and a new class is currently used AppCompatActivity.

In the class itself we see a method onCreate()– it is called when the application creates and displays activity markup. The method is marked as protected and is accompanied by annotation @Override(overridden from base class). The summary may be useful to you. If you make a typo in the name of a method, the compiler can warn you that the parent class does not have such a method Activity.

Let's look at the method code.

Line super.onCreate(savedInstanceState); is a constructor of the parent class that performs the necessary operations for the activity to work. You don't have to touch this line, leave it unchanged.

Second line setContentView(R.layout.activity_main); is of greater interest. Method setContentView(int) includes content from a markup file. As an argument we specify the file name without extension from the folder res/layout. By default, the project creates a file in it activity_main.xml. You can rename the file or create your own file with the name cat.xml and connect it to your activity. Then the code will look like this:

SetContentView(R.layout.cat);

To keep your code neat, try to adhere to standards. If you are creating markup for an activity, use the prefix activity_ for the file name. For example, the markup for the second activity could be named activity_second.xml.