Category Archives: Android

Posts on Android development

Способ разогнать Android Studio

Может кому будет полезно – способ разогнать Android Studio. У меня он дико тормозил из-за сложного layout и большого размера проекта. Кроме этого, на аймаке нет SSD.

Нужно увеличить размер памяти для виртуальной Java-машины. Я увеличил у себя до 2 Гб. Все стало летать.

Создаем так конфиг и внутри пишем:

Причина тормозов – прожорливость Java в плане памяти.

Здесь подробнее.

Snippet to determine a size of control in Android

It is a common task to get a control size. You may need it to create image assets to customize that control.

First we get a control object, for example ToggleButton. Then we get a pixel density of the device. After that we can convert px units to dp units.

6 наиболее важных новинок в Android 5.0 Lollipop с точки зрения разработчика


Официальный выход Android 5.0 состоялся 3 ноября 2014 года. Я изучил новинки Android 5.0 Lollipop, поставил на свой Google Nexus 5, посмотрел своими глазами. На официальной странице все можно посмотреть и понять, правда скрыт факт изменения среды выполнения, так как это информация для пользователей. Просмотрел все популярные обзоры, но наилучшим источником на русском языке оказалась статья в Википедии.

Итак, наиболее важные новинки с моей точки зрения (по убыванию):

  1. Переход на виртуальную машину Android Runtime (ART), официально сменяющую Dalvik для повышения производительности и оптимизации, направленной на повышение энергоэффективности системы. Это ведет к увеличению времени работы батареи и отсутствию лагов во всем. Надеюсь, что правда, сложно проверить.
  2. Поддержка 64 битной архитектуры, 64-битных устройств и систем-на-чипе. Система на чипе или система на кристалле – это электронная схема, выполняющая функции целого устройства (например, компьютера) и размещенная на одной интегральной схеме.
  3. Улучшенные сетевые передачи и улучшенное подключение к интернету везде. Надеюсь, что правда, сложно проверить.
  4. Android 5 Lollipop теперь поддерживает не только смартфоны и планшеты, но и системы в автомобилях, часы и телевизоры.
  5. Еще больше настроек уведомлений. Теперь показывается оценка времени заряда батареи. И другие мелкие настройки, которыми будут пользоваться только гики.


  6. Новый дизайн под названием “Material design”. И он явно лучше, чем то, что было раньше. Хотя новый внешний вид трех главных кнопок мне лично не нравится. Поменялись анимации. Сильно изменилась клавиатура – но не уверен, что теперь она лучше. Вообще, не уверен, что мусолить дизайн и кричать о изменениях в нем как о чем-то крупном целесообразно.
  7. nexus2cee_image36

My visit to a YaC 2014 Conference (Mobile section)

YaC 2014 – Yet Another Conference was organized by Yandex in Moscow in October 2014. It is a largest developer conference in Russia. I have participated only in a Mobile section.

There was a presentation from Orta Therox – the creator of CocoaPods, called “Tools, Testing and new New Team Members. The Story of Post 1.0”. Here is his presentation.

A presentation from Ashley Nelson-Hornstein from Dropbox called “Building Quality Code That Lasts: A Dropbox Story”

and some other presentations from Russian developers.

All materials are published now and available for free.

What I did get from all that is something new about unit and integration testing – using mocks to speed up network connection related tests, information about some new instruments and team development, something new about View stacks and some understanding of possibilities of using JavaScript in a new iOS WebView – WKWebView. Found a new friend – another mobile developer.

Here are some of my own photos:

Android Java Serialization Using Generics

I have created a class – SerializationManager, it can serialize any objects and write them to files. It can be used to save and restore form states in Android. It is based on Java Generics. What is achieved by this is that you do not need to duplicate serialization code in every class.


Object must implement Serialized interface. Here form is an object instance of a class. It can be named as just obj.

This is how you can use it. First you declare a SerializationManager in your class and you tell it which class you are going to serialize:

Then in onCreate method you create SerializationManager instance:

Writing object to a file:

Reading objects from saved file:

A little joke for reading to the end:
java generics

Tips discovered while using Android spinners : setting selected item and finding objects in arrays in Java

To set a selected item programmatically in Android Spinner, you should use setSelection method.

To get an index of an item to select from an array of strings using IndexOf, you should first use java.util.Arrays.asList method.

Complete code:

Serialize an object, save it to a file and read it from a file in Android

Android interface Serializable is not sufficient to save your objects to the file, it only creates streams.

This is a complete code with error handling and handling closes of streams. Add it to your class that you want to be able to serialize and deserialize.

In my case the class name is CreateResumeForm. You should change it to your own class name.

Use it like this in your Activity:

Searching for the best technology for a mobile app backend development

Client-server applications with a mobile app client are more interesting than mobile standalone applications. They offer a new type of features for users like daily updated content. That is why at some moment of my mobile developer career I decided to learn how to create a server side for my mobile applications myself. As it happens usually in IT, there were a lot of techologies and programming languages, that I could start to learn and use for achieve my goals. Of course, if I would stop on the first one, that I have tried, I would lose, because one can never find the best way without understanding what other ways give and without any broad enough knowledge. I think, it is a good idea to get familiar with minuses of each technology before starting to learn and use it.

This is my story. I started with Java Servlets and I have tried also PHP and Python at the moment. Also I have read about Ruby On Rails and Node.JS. Finally, I stopped currently at using Python with Django.

Between Java Servlets and Python I choose Python. Development on Python it is much faster than on Java Servlets. It has no complex and sensible configuration files. Python offers iterative development, you can just refresh a web page and see results instantly. With Java Servlets you have to wait some time every time you update something. Python is like scripting language, despite it is compiled to some kind of byte code. I also liked python for it’s clean syntax, despite I am friendly with Java too. Using HTML templates with Python is easier to me, than creating JSP pages with servlets. Just for information, I use Sublime Text 2 as a Python editor with a Lazy color theme. It is really convenient editor.

I will not try PHP, because it is not valuable now, loses it’s popularity. It looks like Python offers almost the same features but even is better because of syntax, because it is compiled and because it offers full OOP support from the start and you can create all kind of applications including desktop applications with it. Also there are a lot of scientific and data analysis libraries on Python, that can be useful to create sophisticated back-end.

I don’t like the idea of using generally considered to be slow Javascript at the backend in Node.js. Also Node.js needs it’s own HTTP server.

What about Parse, QuickBlox and other ready for use backend services? I don’t want to use them, because I want to be able to create my own-backends with complete understanding of their code and work. These are good to create something easy and usual, but not something unique.

Probably I will try also Ruby on Rails at some moment.

But currently I am completely satisfied with Python. I want to get familiar with Django framework on Python too.

There are also open-source backends like Baasbox: But I haven’t tried it yet. Looks like it is written on Java, because needs JVM.

More articles on this topic:

On TextView Hints and StringUtils.isBlank

I had a problem caused by setting empty or blank strings to the TextView and AutoCompleteTextView – hints were invisible after that. So I decided to check strings, that are set, if they were not only empty, but also not blank. I used StringUtils.isBlank instead of StringUtils.isEmpty: it works much better now, and hints are always visible. If you don’t still use StringUtils, I highly recommend you to do. This is a Gradle import for a library that contains them:

And another example with AutoCompleteTextView:

Here is some information on how isNotEmpty and isNotBlank are working.

Title of this article: On Android TextView and AutoCompleteTextView Hint and StringUtils.isBlank and .isEmpty

I am now a Friend of Eclipse

I was awarded a status of a Friend of Eclipse.

I like Eclipse, since it is free and powerful. I was using it for Android development for free and created a lot of staff, that is why I decided to help Eclipse team. Although I have moved to Android Studio recently, currently I use Eclipse Luna for developing web applications for Google App Engine.