How to create an application for Android. Hello Kitty - Creating the first Android application


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. 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 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 active list 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?

If you are wondering how to create an Android application, it is not as difficult as it might seem. However, you still cannot do without minimal knowledge in programming and code development.

There are many services on the Internet that provide ready-made templates for writing programs, but you can only create a truly profitable application using code.

Before you start developing your first application yourself, the user needs to download and install the following software products.

Installing the Java Development Kit

After installation is complete, you need to open the application and check all uninstalled packages and resources.

In the next step, you must add the Android SDK plugin to the integrated development environment. Using the Eclipse environment as an example, you can add a plugin as follows:

  1. In the “Help” tab, click “Add new software”.
  1. Click the “Add” button and enter the plugin name and address.

  1. Click “OK” and check the box next to “Developer Tools’”.
  2. Click “Next” and start installing the plugin.

After installation, the user will introduce new icons into their integrated environment.

Setting up emulators for testing

The emulator eliminates the need for programmers to have all types of Android devices to test new applications.

This is what the Android SDK looks like

To add a new device, you need to click on the “New” button and create a virtual device by entering basic data and its characteristics.

  • Name;

It is necessary to enter a name that would indicate as informatively as possible what this device is.

  • Target;

Here you need to select the version of Android on which to test.

Advice! Testing is often carried out on the latest versions of the operating system, however, if the programmer decides to do this on earlier versions, then there is a need to install an SDK manager.

  • SD card;

You must specify the amount of disk space that will be used in the device.

  • Skin;

Allows you to create and change the appearance of a virtual device.

  • Hardware;

Adds equipment that will be used during testing.

Creating the first project

Creating the first project on a base integrated among Eclipse development begins with the buttons File - New - Project.

Installing and configuring the Eclipse Android SDK development environment

How to create an application for Android: Instructions for setting up programs

The operating system, called Android, is relatively new. In this regard, we can say that its capabilities have not been fully studied, and not all users “respect” it. But it should still be noted that the speed of this operating system makes it possible to save time and resources. On a mobile device running such a shell, you can do almost everything that can be done on a regular computer.

How to create an application for Android. Main stages

Programming, which is available in the country, can provide a fairly large amount of useful knowledge. Mastering the basics of the system is quite easy. Let's look at the main stages of programming and learn how to create the necessary application for Android.

The first step is to install and configure the IDE for the operating system. This is the main thing to do for users who want to learn the basics of programming through the use of the Android platform. You need to take a few simple steps before creating an Android application.

A few simple steps

  1. Find the platform that fully meets your requirements and download it. After the program is downloaded, install it. It should be noted that will not work if
  2. You need to download the Eclipse Classic application by selecting a specific platform. For example, Windows 64-bit. For better performance of the program, the Android Development Tools plugin is installed in it. To do this, you need to run the utility, open the Help menu and click on Install New Software. After this, a window will open in which you will need to click on the Add button. Then another window will appear in which you will need to enter a name in the name line. In the Location item, you will need to specify a link to the resource where the required plugin is located. When the window is closed, Developer Tools will appear on the screen. Check the box opposite and click the “Next” button. When the next window opens, feel free to click “Next” without making any changes. After installing the plugin, click on the Finish button. For activation to occur, restart the program.
  3. Download the SDK and update to the latest version if necessary.

The next step towards creating

The second step in finding the answer to the question of how to create an application for Android is to create an application that will help with programming. At this stage, several conditions will need to be met.

How can you test the performance of your application?

Have you figured out how to create an Android application and achieved this goal? Now let's check it. In order to test the created application, you should use a virtual smartphone called Android Virtual Device. It will help you display the operation of your application in a visual form on various models of mobile devices.

Using software tools to create an application

What other applications can you use to create an Android application from scratch? Today, there are a huge number of different utilities that will help you achieve your goal. Many of them have a simple, intuitive interface. We should take a closer look at the main programs that are most popular among users developing applications for their operating system.

You just need to have imagination

Are you interested in creating an application for Android, but do you think that this requires good knowledge of programming languages? Everything is not as scary as it might seem at first glance.

The main thing you will need is the ability to assemble virtual construction sets. By using specialized services, which will be described below, you can independently go through such a process as creating an application for Android. In this case, knowledge of programming languages ​​is not required. You just need to assemble it, guided by your imagination, needs and talent.

Free program that allows you to design an application

The Ibuildapp program is rightfully considered an excellent tool that will help you create interesting applications for Android. In order to start working in this program, you do not need to study programming languages ​​or read specialized literature in search of any knowledge. The service has a Russian-language version, which greatly simplifies working with such software. In addition, it is completely free to use. To do this, you only need to select the appropriate operating mode. Thanks to this utility, it is possible to create a variety of interesting applications for Android and publish them on the appropriate resource called Google Play. It is worth noting that there is also a paid mode, but first it is better to understand the free version, and only then switch to the paid one.

We implement our plans using a well-known utility

Another popular application is a utility called Appsgeyser. This is a free tool that will help you create an Android application yourself. The functional part of this software consists of only one task - to “sew” any resource into the application. This is a kind of converter of network portal content into a program, and if the user has his own network resources that need to be transferred to applications for Android phones, then this tool is the best choice.

Thanks to the applications created, it is possible to earn money. To do this, use two methods: sell your development or build advertising into it. Are you into cinema and have a mobile device running Android? An application for a film can be made without much difficulty using such a program. In addition, you can create a utility not only from any resource, but also from a video blog.

Intuitive interface - we work with pleasure

A tool called Thappbuilder can help you quickly create an application for the Android operating system without spending a lot of effort and time. As in the above programs, all functionality will be available in free mode, which is good news for many users. The interface of the utility does not contain anything complicated, it is intuitive, so working with the service will be convenient and enjoyable for users of mobile systems running Android.

An application for movie, pictures, music, etc. can be easily created using the templates provided by the program. They can be altered to suit your taste. It should be noted that the utility may please users with the ability to work in design mode.

The Russian version will simplify your work

The Appsmakerstore program also has a fairly simple and intuitive interface. It allows you to create your own application with a few clicks of the mouse. One of the main advantages of the application is that the program can be adapted for six versions of platforms. Agree, impressive? You can easily and simply create the desired application for Android. The Russian language, into which the names of all tools and tabs are translated, will only help you in designing. The Russian-language version can be provided to users completely free of charge. The utility can use all the tools that are built in here. One difference from the paid version is the lack of full-time technical support.

That's all the basic programs that will help you create an application for the Android operating system. We wish you good luck in using them!

How to create an application for Android - 10 steps + 5 websites + 10 tips for beginner programmers.

People who know how create an application for android, can earn very good money.

Learning how to program and create games, libraries, and online stores is not difficult.

This article will explain all the steps a beginner should take to create an app that will attract a large number of subscribers.

Steps to creating an Android application

After studying all the necessary steps, you can create your own program and put it up for sale.

Think about an original topic.

In order for an application to sell well, you need to make it not only convenient and beautiful, but also unique.
Otherwise you will have a lot of competitors.

Prepare to fail.

Most likely, the first pancake will come out lumpy.

Carefully test the result of your work.

Users can express many opinions, both positive and negative, and this opinion is worth listening to.

Select your age audience.

An application for a child should be brighter and more colorful than for an adult.

Give lots of information and menu options. People love to wander around pages, exploring the tabs.

Few people will like a one-page program.

Don't charge too much for your first job.

First you need to fill your hand.

How to write an application for Android?

Almost anyone can become a developer of various games and programs.

For some it will become a job and a profitable business, for others it will be just a hobby.

However, as practice shows, those who are seriously interested, study the topic and create games carefully, step by step, achieve great success.

To become a developer, you need:

  • To work you will need a personal computer with Internet access.
  • The assessment can only be made from a mobile phone on which the latest version of the Android system is installed.
  • Knowledge of English at least at a minimum level is desirable.
  • Knowledge of the Java language is required.
  • Knowing XML markup will make your work easier and allow you to create colorful, beautifully designed programs.

All the described stages can be combined into three main ones:

  1. Development of the program interface, selection of images.
  2. Working with code.
  3. Testing.

Each stage is important in its own way and should not be skipped.


Some may decide that there is no point in spending time on the concept.

But no one sits down to write a book without knowing what it will be about?

An idea for a game or program needs to be developed and all weak points filled.

It should be understood that there is no clear answer to the question: how to create an application for Android.

It’s not enough just to create it, you need to make the program interesting.

Modern websites allow you to quickly create what you have in mind without struggling with code.

For amateurs, this option is quite suitable.

If you want, you will have to do everything yourself.

The testing phase should also be given due attention.

Analysis of the opinions of testers allows us to draw a conclusion about how owners of Android smartphones will perceive the new product.

How to create an application for Android and promote it?


If you are not a popular blogger or creator of large games, then at the initial stage you will have to devote time to promoting the created program.

For the fastest spread, you should:

  1. Use cross-references with other owners of social networks and blogs.
  2. Post links on your own blog.
  3. Tell your friends about the created program.

The video below shows the process of creating an application using the Appsgeyser service:

Many people don't know how to create an application for android, and are afraid of the phrase “programming language”.

However, there is nothing scary or difficult in developing programs.

Modern online sites perform all the necessary actions, you just need to give them direction.

Mobile software development can be a fun and rewarding endeavor. In this article we will tell you how to create an android app.

Android Studio

To write an application, you will need to download and install Android Studio. The package includes a software development kit with all the libraries and Android code needed to develop the application. And also an Android emulator, which allows you to first test the application on your PC without installing it on a real mobile device.

But first you need to download and install the Java Development Kit ( JDK) from Oracle. Find the section " Java SE Development Kit 7u79» and download the version for your PC. It is important to download the correct version ( 32-bit or 64-bit), otherwise Android Studio will not be able to find the Java Runtime Environment ( JRE).

Note: Oracle will not be publishing any updates to Java SE 7 on its public sites, and users are expected to migrate en masse to Java 8. But currently Android Studio requires Java 7. This may change in the future.

After you have installed the JDK, you need to install Android Studio. During installation, you must specify how much memory to reserve for the Android emulator. It runs Android as a virtual machine, like an Intel-powered smartphone. This is faster than ARM processor emulation on PC. But to run this virtual machine, the emulator must allocate some memory. But before you create an Android application yourself, keep in mind that the combination of Android Studio, Java and an emulator will be quite resource-intensive, and the computer may slow down.

Google says at least 2GB of RAM is required, and 4GB is recommended. But my main PC has 8 GB, and it still slows down sometimes:


When you first launch Android Studio, it will perform initial initialization, which includes downloading and installing the latest version of the Android SDK. This may take a few minutes.

Once everything is downloaded and installed, you will see a menu that allows you to create a new one, open an existing one, or import a project, etc.

Create a new project

Click " Start a new Android Studio project" and enter the name of your application in the field " Application name" In field " Company Domain» Enter the official domain of your company. If you are an independent developer or hobbyist, enter your own domain. If you're just experimenting with Android and don't plan to publish your apps to Google Play anytime soon, just leave the example domain, just change the " user" in your name (without spaces):


In the next dialog box, make sure you have the " Phone and Tablet", and for " Minimum SDK» installed - API 15: Android 4.0.3. For options " Wear" And " TV» checkboxes should not be checked.

In the dialog box " Add an activity to Mobile» leave the default value « Blank Activity" and press " Next" In the dialog box " Customize the Activity" Leave all values ​​and click " Finish»:


Integrated Development Environment ( IDE) is running. This may take a few minutes ( especially if this is your first time creating a project). If you see the error message " Rendering Problems: Rendering failed with known bug", click the link " rebuild" that appears next to the error message.

By default, the IDE's workspace is divided into three main parts ( not counting the toolbar, etc.). At the top left is the project tree. To the right of it is the code editor, and below them are messages.

Before you create an Android application from scratch, you can already compile and run the automatically created application, but this is not very interesting. Instead, we'll add a few tidbits to get you started with Android app development.

Project tree

The project tree contains all the files and resources needed to create an Android application. If you're familiar with writing simple programs in Java, C, Python, etc., you might think that everything would be contained in just one or two files. But Android app development is a little more complicated:


At node " app The project tree contains several nodes (for example, folders) that can be expanded. The top level nodes are “ manifests”, “java" And " res" The latter is an abbreviation for “ resources”.

IN " manifests” the file is located “ AndroidManifest.xml", every application must contain it. This is an XML file with information about the application, including its name. An element often added to this file is a list of permissions required by the application. For this simple application, you don't need to change anything here.

In chapter " java» contains the Java code of the application. It will be in a subdirectory called com.example.user.myfirstapp. This is the company domain name you entered earlier, but in reverse, plus the application name. This folder contains the MainActivity.java file. This is the entry point to the application and the only Java file we will need.

We continue to create a simple application for Android. In chapter " res» There are several folders for graphics, menus and UI elements. We are interested " layout" And " values" In folder " layout" there is a file called " activity_main.xml" This is an XML file that describes the user interface. You can edit it in two ways. The first is to directly edit the XML code, the second is to use the built-in UI designer:


In folder " values"contains several XML files. At the moment, the most important thing for us is strings.xml. Instead of setting string values ​​in Java code, they are usually placed in the file " strings.xml", and we can refer to them through identifiers. The advantage is that if a string is used multiple times, it can only be changed once and the changes will take effect in all places. This also makes it easier to support multiple languages ​​within the app.

To create an Android application yourself, you will need to change the MainActivity.java, activity_main.xml and strings.xml files.

Writing an application

For our example, we will add a button labeled " Tap Me!", change the default greeting " Hello world!" on " Tap me if you dare!" We will also change it so that it is in the center. And let's add the code so that when the button is clicked, the text " toast»!

Let's start by changing the greeting text and its alignment. First, find the file “ activity_main.xml» and double-click on it. Remember, that " activity_main.xml" is a file that contains the user interface definition. At the bottom of the code window there are two tabs: " Design" And " Text" Go to the " Design».

Now click on the text " Hello world!", which is shown in the preview window of the smartphone screen. If it is too small, use the zoom button ( magnifying glass with plus sign).

In the properties window located to the right of the phone image, scroll down the screen until you find the words “ layout: centerInParent" Click on the space bar next to it and select " horizontal" After this the text “ Hello world!» will move to the center:


Before creating an Android application without skills, let's change the text. Line " Hello world!" is stored in the file " strings.xml" in the res->values ​​section. If you double-click on this file, you will see several XML lines that define the strings used by the application.

Find this line:

XMLSELECT ALL XMLSELECT ALL Hello world!

And change it to:

CSSELECT ALL CSSELECT ALL Tap me if you dare!

We've changed the greeting's alignment and text. Now let's add a button. Return to the " Design» file « activity_main.xml", find in the list " Palette"To the left of the smartphone image is the item " Button" and click on it. Now click somewhere under the words “ Tap me if you dare!».

Double-click a button to change its text. At the end of the field “ text:” there is a button with three dots, click on it. In the window " Resources» click « New Resource", and then " New String Value…" In field " Resource name:" enter " tapme", and in the field " Resource value:» — “ Tap me!" Then click " OK" Now we have a button “ Tap me!”.

The last step in creating a simple Android application is to add Java code that responds to button clicks. One of the Android user interface elements is “ toast." It provides a simple message in a small popup window. You've undoubtedly seen this. For example, in Gmail, when you sign out of email before sending the email, you see the message “ Message saved to drafts" After a certain time it disappears.

For our example application, we will display a message every time a button is clicked. The first step is to add the Java code. Find the file " MainActivity.java" and add the following code to " onCreate«:

JAVASELECT ALL JAVASELECT ALL public void onButtonTap(View v) ( Toast myToast = Toast.makeText(getApplicationContext(), "Ouch!", Toast.LENGTH_LONG); myToast.show(); )

Word " View" in the phrase "( View v)" will be red and a message will appear next to it indicating that you have used a new design ( View), without importing it in the import section, at the top of the Java code. This is easy to fix. Click on the word " View" and then ALT + ENTER. If the word “ Toast” is marked in red, do the same again:


Return to the file designer section " activity_main.xml", click the button and scroll the list of properties to the item " onClick" Click on the box on the right and a list of functions will appear on the screen. Click on " onButtonTap", this is a feature we just added.

Now the onButtonTap() function will be called whenever the button is clicked. To display the message, we call myToast.show() .

That's all for creating an Android application yourself, now let's test it in an emulator.

Building and testing the application

On the menu " Tools» Go to Android-AVD Manager. This tool displays a list of currently configured virtual Android devices. You will have one device configured by default, probably a Nexus 5. Click on the play icon (triangle) in the " actions" This will launch the emulator.







2024 gtavrl.ru.