How to start developing for Android. Efficient use of memory

But first, we'll tell you why users choose , and not Oreo or Pie:

  • Compared to regular Android Oreo version, it is faster
  • It requires less device memory
  • It requires less RAM.

Now that we've sorted out the reasons, let's move on to the principles of application development.

Check the connection quality

In general, the ability of an application to request and provide information depends on the quality of the Internet connection. We are not ripping off any covers here. Therefore, before downloading data, it is necessary to monitor the status of the Internet connection.

You can do it this way:

And this way you can find out the status of the Internet connection, its quality, and also check whether the device is connected to the metered network:

Pay attention to the quantity and quality of requests. The worse the connection, the lower the resolution of the media content should be.

The APK file size should be as small as possible

Users are not always able to download applications with large APK file sizes. And sometimes they avoid cumbersome applications altogether. After all, everyone understands perfectly well that the size of the APK file affects the download time and memory load.

Try to keep the APK file size below 10 mb. After all, one of the best ways to reduce the size of your application is to reduce the number of resources involved.

Now let's talk about how to do this. You can change the amount and weight of resources in the APK using the Lint tool. Lint is a code analyzer for Android Studio. It finds (but does not delete) resources in the res/ folder that are not referenced in the program code. However, keep in mind that Lint does not scan the assets/ folder.

In the console, Lint is launched using the command:

Dependencies you add to a project may contain unused resources. Gradle automatically removes them if you use shrinkResources in your application's build.gradle file. To remove unused code, you should use ProGuard minifyEnabled. For more code optimization, you can also try specifying the rules file 'proguard-android-optimize.txt' instead of 'proguard-android.txt' :

You can also reuse resources. For example, if you need two resources that differ only in the rotation angle. Take just one of them and rotate it the required number of degrees:

You can also reduce the size of PNG resources in the res/drawable/ folder using the aapt tool:

Use vector graphic assets as they significantly reduce the size of the graphic assets in the APK. However, remember that large vector images take longer to render, so only use them to display small images.

Efficient use of memory

To ensure that the application does not crash due to Out Of Memory, you can find out what heap size is available for it (memoryClass), as well as whether the device has a low amount of RAM (1GB or less) (isLowRamDevice):

You can find out the memory status using:

To monitor memory usage, you can use the Memory Profiling Tool in Android Studio. Using this tool you visualize the processes taking place:

In the figure we see how much memory graphic resources occupy in the application (20.1 Mb). And of course, it's good practice to use low-resolution images.

Next point. Clear memory when the GUI leaves the screen or when there is simply not enough memory. To do this, override the onTrimMemory() method of the ComponentCallbacks2 interface and, depending on the event type, clean up the unnecessary:

The onTrimMemory() method is called when the operating system determines that it is necessary to trim the unnecessary memory of one of the processes. For example, when a process becomes background and there are not enough resources for other background processes.

Optimize your battery usage

Try to limit operations that quickly drain the device while the device is not connected to a power source. You can know when the device is connected to power and know the battery level. Let's declare in the BroadcastReciever application manifest:

PowerReceiver class:

You can also react to the battery level. Let's declare in the application manifest:

BatteryStateReciever class:

You can see how an app uses battery using Battery Historian:

The application must be fast and responsive

In addition, we note that the user always needs feedback - the application must respond to his actions. What is needed for this? When starting the application, we provide a placeholder or a special loading screen. In this way, the user will pass the waiting period. It's a small thing, but it's much better than staring at a blank screen.

This means we will avoid empty states and fill the screens with placeholders or images. However, do not forget that devices with small screens have small computing resources. And to increase productivity, you should reduce the use of volumetric images and animations. Make sure your screen refresh rate is 60 frames per second and use Profile GPU Rendering to do this.

Conclusion

Following the recommendations listed in this article allows you to create an application for Android Go that will help the user save resources (memory, traffic, battery power) and make the experience of using the application enjoyable in every sense.

In addition, our tips help improve app ratings and audience retention. After all, no one needs a product that is slow and too demanding on device resources. As a rule, it is removed after the first negative experience.

The application does not close when you go to the desktop; it continues to hang in the device’s memory, but with a different priority.

I wanted to write an article on this topic, but... I’ll brazenly quote the words from the first book I came across (this information can be found in the “Processes and Application Life Cycle” help):

Processes with the lowest importance are killed first. There are five levels in the hierarchy of importance. The following list presents them in descending order of importance.

1. Active process(Foreground Process). A process is considered active if any of the following conditions are true:

The process runs an Activity with which the user interacts;

A process runs a service associated with the Activity that the user is interacting with;

The process has a Service object, and one of the callback methods defined in that object is executed;

The process has a BroadcastReceiver object and its callback method is executed to receive the Intent.

Only a few priority processes can exist at the same time. They will be destroyed only as a last resort - if there is so little memory that they all together are not able to continue working.

2. Visible process(Visible Process) - a component from this process can still be called by the user. This could be an Activity that is not in focus but is still visible to the user. A visible process can also be a service process that is currently associated with an Activity that is in the foreground (or partially obscured by another Activity). This can happen, for example, when calling a dialog that does not take up the entire screen when the Activity has lost focus, but is visible to the user and is behind the dialog. The visible process is considered important and will not be killed as long as lower priority processes remain.

3. Service process(Service Process) - a process in which a Service is executed and which does not belong to one of the two previous categories. Although service processes are typically not tied to a user-visible interface, they perform tasks required by the user, such as running a media player in the background or downloading data from the network, so that the system stores them when there is free memory along with all active and visible processes.

4. Background process(Background Process) - the process in which the Activity is running, which is currently not visible to the user. These processes have no direct impact on user input and can be killed at any time to free up memory for the active, visible, or service process. There are usually many background processes, these are stored in an LRU (Least Recently Used) list to ensure that the process at the end of the list running the Activity is the last to be killed.

5. Empty process(Empty Process) - does not contain any active application components. The only reason to save such a process is to use it as a cache to reduce startup time when calling a component. The system destroys these processes first.

If multiple components are running in the same process, Android determines the priority of the process based on the component with the highest priority. For example, if a process is running a service and has a visible Activity. If other processes depend on a certain process, its rank can also be increased.

How does the Android development process work? Let's highlight a few basics:

  • In Java files, you describe program logic—what you want your application to do.
  • In XML files you develop layouts - the appearance.
  • Once the app 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 will open to edit your code files and compile and run them.
  • Previously, the standard IDE for Android development was Eclipse, but it has now been replaced by the more functional Android Studio, a Google product.

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 there will be links to useful resources that every Android developer should be familiar with. The first one is the official documentation from Google.

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

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

Installing the Android Studio development environment

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

For those new to Android programming, it is especially important to take your 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. One can especially highlight the resource StackOverflow.

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

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

Go to Android Studio developer.android.com/studio/index.html and find the 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 carefully reading (as you always do) and accepting, the download begins. This will probably take a few minutes. After this, you can install Android Studio just like any other program. The initial download page contains installation instructions for Mac and Windows.

Now that you have Android Studio installed, let's launch it! Launch Android Studio. The program will ask if you want to import your settings. Since you're starting from scratch, just select the second option and continue.

You should see a beautiful loading screen in Material Design style.

Once the download is complete, you will be taken to a 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 obtain the latest version. Sometimes Studio will automatically inform you that there is an update with a screen like this:

In this case, always select Update and Restart. Great! We have successfully completed the installation of the development environment.

Creating the first Android project

It's time to create the first project. Let's start with something simple. Programmers usually call the first program “Hello World”. Let's follow this tradition and then make a few small changes to make the app use your name as a greeting. At the end, you can download it to your device and show it to your friends. Android Studio has a small step-by-step tool that will help you create your project. Click "New Project" on the start screen:

Fill it out 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 pointing to any folder on your hard drive

For drop-down SDK versions, note the Description section at the bottom of the dialog box. It explains what each setting does.

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

For more information about API versions and their use, there is a special Dashboards page on the website for Android developers https://developer.android.com/about/dashboards/index.html.

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

And now you are at the last step of the application creation process. Before you click Finish, pay attention to a few things. This is the first time you 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 thought of as a "screen" in your application. This element is very flexible. When Android Studio creates the MainActivity class, it inherits it from the Activity class in the Android SDK. Those familiar with object-oriented programming will understand this concept, but for beginners, this basically means that your MainActivity will be a customized version of the Activity.

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

Click Finish. It will take some time to create and download the project. After some time, 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 layout file in XML format. Before we move on to Android programming, let's talk about how we can run this application. It's time to say "Hello world!"

Running an application on an emulator

Now it's time to say a few words about the emulator. Android Studio comes with software that can emulate an Android device to run apps, browse websites, debug, and everything else on it.

This feature is provided by Android Virtual Device (AVD) Manager. If you wish, you can set up multiple emulators, set the screen size and platform version for each new emulator. This functionality is very useful because it saves developers from having to buy multiple devices to test programs.

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

You'll have to wait a while for the emulator to load and once it's ready, you'll see something like this:

Congratulations! You've made your first Android app!

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

To start making changes and adding interesting features, you need to gain a working knowledge of what's going on behind the scenes. Take a look at the Android Studio project section with files and folders 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 visible.

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

Android project structure: Team

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

Java: Professional

This is the part of your code that is responsible for the application logic. Your code will be located in the src\main\java directory in the main project folder. To learn Java, I recommend Bruce Eckel's book "The Philosophy of Java";

Resources: Artist

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

When initialized, the folder contains the following folders:

  • drawable, which stores icons. Now there is only the 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 of the application's hardware and software requirements and contains its version name and icon. The manifest also contains information about all Activities in the application. Do you need the work done by your application? Talk to your boss first.

Making changes

Navigate to res/values/strings.xml and double-click 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 fellow marketer asks you to remove all the unnecessary links, it's easy to make all the changes here.

Change the hello_world string that the application displays on the screen. Change the content to something more personal, such as using your own name. You'll get something like:

Matt is learning Android!

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

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

This tutorial will teach you the basics of how to write an Android application using the Android Studio development environment. Android devices are becoming more and more common, and the demand for new applications is only increasing all the time. Android Studio is a free, easy-to-use development environment.

For this tutorial, it's best if you have at least a passing knowledge of Java since that's the language used by Android. There won't be too much code in this tutorial since I'm assuming you have some knowledge of Java or are ready to find something you don't already know. Creating an application will take 30-60 minutes, depending on how quickly you download and install all the necessary programs. After following this tutorial on how to create your first Android app, you may find yourself a fun new hobby or even start a career as a budding mobile app developer.

Stage 1: Install Android Studio

  1. You need to install the JDK ( Java Development Kit) and JRE (Java Runtime Environment). You can download it from this link. There you select the version for your OS, accept the license agreement, download and install.
  2. Now go here http://developer.android.com/sdk/index.html and download (be careful, you will have to download about 3 gigabytes).
  3. We start the installation and follow the instructions.

Stage 2: Create a new project

  1. Open Android Studio.
  2. In the menu " Quick Start", select " Start a new Android Studio project».
  3. In the window " Create New Project"(the window that opened), name your project " HelloWorld».
  4. Company name optional.*
  5. Click " Next».
  6. Make sure the checkbox is only on " Phone and Tablet».
  7. If you are planning to test your first application on your phone, then make sure that the correct version of Android is selected (not older than the one on the phone).
  8. Click " Next».
  9. Select " Blank Activity».
  10. Click " Next».
  11. Leave all other fields as they are.
  12. Click " Finish».

*Typical company name for Android projects is “example.name.here.com”.

Stage 3: Editing the greeting

  1. Go to the tab activity_main.xml, most likely it is already active.
  2. Make sure the tab at the bottom of the screen is active Design(most likely this is true).
  3. Drag the phrase " Hello, World! » from the top left corner of the phone to the center of the screen.
  4. On the left side of the screen there is a folder tree. Open the folder called " values».
  5. In this folder, double click on the file " strings.xml».
  6. In this file, find the line containing the text “ Hello world!" and add to this text " Welcometomyapp! ».
  7. Return to the " activity_main.xml».
  8. Make sure your text is centered on your phone screen and contains the text " Helloworld! Welcometomyapp! ».

Step 4: Add a Button

  1. On the " activity_main.xml" select the tab " Design».
  2. In the column to the left of the window where the phone is located, find a folder called " Widgets" There are various buttons there.
  3. Grab the " Button» and drag it onto your phone screen. It should be centered on the screen right below your text.
  4. Make sure the button is still selected (blue frame around it).
  5. In the lower right corner there is a window with the properties of the selected object. Scroll down and find the line called " text».
  6. Change the text " New Button" to " Next Page».

Stage 5: Create a Second Activity

  1. At the top of the project's file system tree, right-click on the folder called " app».
  2. Select New > Activity > Blank Activity.
  3. In the window that appears, in the top line, enter “ SecondActivity».
  4. Click " Finish».
  5. Go to the " activity_second.xml" and make sure the " tab is selected at the bottom Design».
  6. Move the text from the top left corner of the phone to the center of the screen as we did in the previous steps.
  7. Make sure the text block is still selected (blue frame) and in the lower right corner of the object's properties, look for the line " id" and enter there " text2 ».
  8. In the upper left corner (in the project tree), double-click " strings.xml».
  9. Below the line Hello world! Welcome to my app!

    add the following line

    Welcome to the second page!

  10. Return to the " activity_second.xml».
  11. Select the text block again.
  12. In the lower right corner of the object properties, find the line “ text" and enter there «@ string/second_page».
  13. Make sure the text box now says " Welcometothesecondpage! ” and the blog is located in the center of the screen.

Stage 6: Write the action for the button


Stage 7: Testing the application

  1. In the toolbar at the top of the Android Studio window, click on the green play symbol.
  2. In the window " ChooseDevice» select the item « Launchemulator» and select the device.
  3. Click on the button OK».
  4. When the emulator starts (this may take a long time), the application will automatically open on the virtual device.
  5. Make sure all text is displayed correctly and that clicking the button takes you to the next page.

Attention: If you receive the message " HAX kernel module is not installed!", then there are two possible options. The fact is that only modern Intel processors support this virtualization and you only need to enable it in the BIOS. If you have a processor that does not support this function, you will have to test the application on a real phone or use a third-party emulator rather than the built-in one.

How to get .apk file in Android Studio

In my opinion, this issue is well covered in this article, so I will not repeat it. I found it easiest for the first lesson Manual method.

Once you receive the file, you can copy it to your phone and install the application.

Stage 8: Result

Congratulations! You've just finished writing your first Android application with some basic functionality. The finished application should have a user welcome page and a button that will take the user to the second page.

You have briefly become acquainted with the development of applications for Android and may have awakened in yourself the desire to learn everything that is necessary in order to further develop in this direction.

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 to create 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 straightforwardly 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 subjects: 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 - a 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.