When developing for Android, many newbies face difficulties arising from the huge variety of devices on which this operating system is installed. This post will explain how to eliminate most of the problems associated with fragmentation of the screen resolution, performance, physical size and version of Android.

1. Tablets and phones. Interface planning
One of the main differences between devices based on Android is the physical size. The “Zoo of Devices” contains both tiny phones and huge ten-inch tablets. And about this extremely important moment, many novice developers often forget.
')
The fundamental difference between phones and tablets is how the user keeps them:
Phones in portrait orientation
Usually held in one hand. Pressing is done with the thumb of the same hand. The finger reaches everywhere, but the lower half of the screen is intuitively convenient.


Phones in landscape orientation
Usually hold with two hands. Pressing is done with the thumbs of both hands. It is convenient to get controls in any part of the screen.


Tablets in any orientation
Most often, regardless of the screen orientation, they are held with two hands. The control comes with thumbs, which cover only two arcs in the corners of the bottom half of the tablet.



Small tablets
Sometimes, if the tablet is not very big, it is held with one hand, and control is exercised by the index finger of the other hand. Pulls out a finger everywhere, but the upper half of the screen is intuitively convenient. It is worth considering that in this way people hold the tablet rarely.


That is, when designing an interface for the convenience of most users, the most important controls should be placed in the lower half of the screen closer to the edges.


2. Screen resolution. Texture stretching
This item is important mainly in the development of games, rather than normal applications ...

With such a variety of resolutions, several problems arise. Here are some of them:
Problem 1. Image clarity
For the graphics of your game to be good enough on any device, you have two options. Either you draw vector graphics, or draw, and then stretch the raster. If you chose the second path, then initially draw it for a large resolution (for example, 1024x768), because when compressing an image, the image sharpness suffers less than when it is stretched.

Problem 2. The correct location
Do not use any "magic numbers" in the code. The calculation of the location of the object should be carried out after stretching the graphics. The coordinates of the objects should depend on the coordinates and sizes of other objects. This is especially important if you want the round to remain round and the square to square.
Here is an example of determining the coordinates of a button from my next game.
againButton.setPosition(table.getX()+table.getWidth()/2-againButton.getWidth()/2,table.getY()+table.getHeight()-5*againButton.getHeight()/4);
Problem 3. Box2D physics
In my previous game, I used the physics engine Box2D, and during testing I discovered a bug related to the screen resolution. In Box2D, the PixelToMeterRatio constant is used when emulating physics. It determines how objects behave: like a box the size of a box, or like a box the size of a skyscraper. Initially define this constant depending on the screen resolution.

Problem 4. Proportionality
When compressing or stretching textures, it often happens that the relationships of the parties change. For example, from 16: 9 to 4: 3. Because of this, some objects can become ugly. To avoid this, make the graphics minimalist, cartoon-drawn. It will help to look like a compressed picture is not so terrible ...
3. Performance
If you are going to make a 3D supermaster, then know that not all devices will pull, but most new phones and tablets will cope without difficulty. Also take into account the fact that not all devices support OPEN GL 2. Approximately 10% of devices support only OPEN GL 1.1.
The main problem with performance lies in another: on different devices, the application has a different FPS. And if for ordinary applications it is not so critical, then for games it is a very important issue. In the game that I am developing now, I ran into a problem: on different devices the speed of movement of the main characters of the worms is different. After long fights and tests, it turned out that this is due to the fact that I move the worms by a certain number of pixels per frame, and with different FPS this gives a different speed ... This bug was fixed by tying the "step" to the current FPS:
shipConfig.setShipSpeed(activity.mCamera.getHeight()/(shipConfig.timePerCameraHeight*fpsCounter.getFPS()));
Again, when developing for Android, make the code extremely soft. Any "number out of nowhere" is reflected in the most unexpected places.
4. Android version

Here are the statistics of the versions of the operating system on which my previous game stood.
As you can see, the majority of users who play games have quite new versions of Android. So this item does not cause any problems.
5. Conclusion
Fragmentation of devices, though it is a developer’s headache for Android, but if you look, problems can be easily solved. With the beta test, be prepared that despite the full compatibility declared by Google, on some devices the application will refuse to work at all, do not despair.
I hope that at least one of the advice I have outlined will help you not to make mistakes that I encountered.