Hello! I would like to share with you my experience of creating the first Android application. And if you have been looking at this platform for a long time, but for some reason still you do not dare to start developing your applications, then I hope my topic will push you to this. Under the cut, there are five reasons why there is no need to doubt and it’s time to act and some more interesting moments.
Initial data
Web developer on sabbatical. Knowledge:
- HTML / CSS is above average
- JS - medium
- PHP is above average
+ absolutely small knowledge in C #. Where does Java ask the reader? Knowledge of this language before development, alas, could not boast. And here is the first reason for you to start developing now -
“It’s not necessary to read a thick manual on Java” .
')
Book: “Google Android. Programming for mobile devices. Sure to? No, if you are friends with English, there is enough documentation on the site. If all the same with English everything is bad, like, for example, mine, my advice to you, do not read the book from cover to cover, repulse all desire. Use as a reference material - in this regard, it is very useful. Reason Two:
"It is not necessary to buy a book if you are fluent in English .
"Device: HTC Desire Z. And what without it in any way? I also thought so, so I saved some money and bought it all the same, but in the end my application started on the emulator and the final result was the same as on the smartphone. Therefore, the presence of the device is not critical, but if there is an opportunity, then it is better to purchase it. The third reason:
"It is not necessary to buy a smartphone .
"purpose
The goal to conquer the planet was not asked, sorry. I wanted to make a simple graphic editor for ala Paint and understand how the android applications are designed from the inside. I didn’t ask any deadlines, but looking ahead I’ll say that it took a little more than a week to complete with the study.
Process
I will not describe the process of installing and setting up a workplace, since this issue and its solution have been voiced more than once. To create an editor, I needed to understand how Android works with graphics. And the first thing that came to mind was games. After all, there is a constant work with graphics, which I began to study.
The first request to google, I came across such a
simple game template . Unpacking the archive, I began to study the source. Looking at the bizarre super instead of parent, declaring classes in a class, and redefining methods while creating objects, you involuntarily think about whether to turn back? But we just do not give up.
Having understood what was happening, I created an application framework based on this template and began to create. Pretty quickly, I found an article about the
interaction with the touch screen and how the child was happy how circles appear under the fingers. I poked at the screen for about an hour, no less. Then, without hesitation, I removed the screen cleaning and left only the render, assuming that now the screen will not be cleared and, accordingly, everything that the user draws will be added to the already drawn one. In principle, it was so, but it was somehow strange. With a long press, the circles turned out to be dense, but with a light touch, the left circle flickered. As I understood, the problem was connected with the change of screen buffers and such a clumsy approach, like mine, will not work here. It was necessary for something else.
The solution was found in a very timely manner in the
Sketcher source code. It consisted in drawing on the surface based on the image and its subsequent transfer to the working surface. This application was just a gold find, for which the author (
WarGoth ) thank you so much! Later I worked relying on him. And also, without changing, I used the color selection dialog. And here is the fourth reason for you:
“There are a lot of source codes of ready-made android applications online and you won’t be left without food for your mind .
”In principle, half of the work was done - the application was already skillfully drawn, it remained to make the interface, menu and form work with the user, which I did for the next four days. I think it makes no sense to describe the whole process, there is really a lot of information about all this. You don’t need to go far, almost all the necessary knowledge I gained here on Habré. In the process, there were questions that I almost always found the answers to
stackoverflow . And this is the fifth reason for not postponing the study of the platform on the back of "
Almost all the questions arising during the development can be answered .
"That’s basically all and I’m probably a captain. But it is, and more and more often the authors of new articles are already telling obvious things, which means that there is already enough information to start. Therefore, stop thinking - it's time to act! Of course, if the community will be interested in any specific points on the application, I can describe them in a separate article, but so far I don’t see any reasons for this.
Total
Eight days passed from the appearance of the idea to the creation of the application, and for two more days I prepared the application for launch. During this time, I learned a lot about the platform, the language and the intricacies of the applications, and I had a desire to write something else. Of course, my knowledge in layout and programming helped me greatly, but it seems to me that the main thing here, as in any business, is not knowledge, but desire.
And finally, tips to help avoid headaches:
- You should not store important variables in streams, they die at the first opportunity. Probably I would know about it if I read the same manual on Java. The solution was to transfer the variables to the class of the form
- If you want your application to react to screen rotation, think about it beforehand, because when you rotate the application restarts completely, decide how you will save the state
- When programmatically changing the selected value in the combo box item (Spinner), the onOptionsItemSelected event is triggered and it is not clear where it comes from, from the user or from the application. The solution was to extend the Spinner class and redefine the OnClick method, which is called when a user selects an item.
- Use styles for markup, it can be a great help when changing the interface or, for example, when localizing, if the labels do not fit on the screen
- Use resources to store string variables. Then localization will not cause any problems.
- Use the Android system resources, so as not to produce icons, texts, and more. I often met copies of system icons in source codes. Resources are available through android.R in the code and android / markup
- When using animation, hide objects that require active redrawing, such as Surface, otherwise the animation will hopelessly slow down
Now about the application itself. This is the usual "drawing tool" with the ability to customize the brush, save the result and share it with friends. It does not claim to be genius, but it seems to me that it is not deprived of the right to be laid out on the market. Please do not judge strictly, as the firstborn.

And now, nice, I hope, a surprise.
The source code of the application is open . It is not perfect and badly commented, but over time I will fix it all. Use on health!
Thanks for attention.
UPDIn the comments I add interesting links and rakes. I think it is worth adding a post:
Sources of code for how-to-do:Possible rake- SQLite is not as fast as it seems. At tens of thousands of records begins to limply shamelessly. Only the right indexes can help.