Caucasian cuisine: problems and solutions

    Hello to all Khabrovites! I am glad to inform you that the company I work for has released the Caucasian cuisine application for Android. Now your favorite dishes will always be at your fingertips. I was involved in almost the entire application development process and would like to share the details with you. First, I want to talk about the application itself, and in the second part of the article about the problems encountered during the development and possible solutions. As a result, those who are interested in the application can read the first part, and those who are interested in the second development process. Go!

    Overview of the application

    Screenshots and the application itself can be viewed as usual in the market -

    Using the application, you can quickly find your favorite recipe and cooking method (there are a little more than 200 recipes in the database). In addition, with the help of an assistant, you can quickly find recipes for the products you have, with a hint how many ingredients are in the recipe found. With the help of the basket, you can save the products you need, or add your own, after which, starting the preparation of a recipe, set the timer and start rolling up your sleeves. You can add ingredients to the basket when viewing the recipe (in the first tab after selecting the category of the recipe and the recipe you like), and the new products added to the basket will be displayed in the assistant with everyone else. And of course, you can keep all your favorite recipes in your favorites, for quick access to them. When you select all the recipes, a search bar appears, which will help you quickly find the right recipe. Such a convenient application that will help you cook your favorite dish.

    I will add that the version of the application will soon be updated, in which it will be possible to share thoughts about using the application with your friends via Facebook, Twitter or VKontakte and a couple of other goodies.
    If you notice any bugs, please write about this in comments or mail.

    Development. Difficulties and possible solutions

    Tabs and several windows
    As you may have noticed, navigation through the application is carried out using tabs. But many tabs have several windows. The difficulty lies in the fact that if you do not clean running windows during transitions, the view hierarchy will exceed the permissible value and the application will drop. To do this, you can create your own class inherited from TabActivity (which inherits the main application window, where all the tabs are), which will override onBackPressed () as needed, or call finish () yourself on transitions.
    Also, there was a problem with customizing the appearance for one tab. In fact, there is nothing complicated in this, you just write your layout with views and style it as you like by passing it to the tab.

    Activity states

    According to some authors, most often (and all that you basically need) the states onCreate (by itself), onStart () and onPause () are used. Yes, indeed it is, but in our application the timer also works in the background and when the window is destroyed (when onDestroy () is called, it resets the state to the database, so that it can resume when the application starts). The authors of Pro Android 2 claim that this method may not be called in everything, like onStop (), so be careful and study the window's life cycle thoroughly. You could write a service for the timer, as an option to solve problems, but then others could arise.

    Gradient Image

    Some images in our application contain gradients and by default (at least in my emulator and on real devices) the gradients blur into stripes, which looks creepy. The solution to the problem, as it turned out, is simple: set the window palette. And you can do this by overriding the onAttachedToWindow () activation method by adding the following lines to the method: Do not forget about Handler If you need to display something in the UI stream, and you are not in the activation context (this is certainly not an Android way), you cannot dispense with this class. Another option is to use AsyncTask. Although there are many more options for using this class (for example, a queue of threads that update UI elements). Keyboard event call programmatically

    super.onAttachedToWindow(); //не забывайте всегда вызывать версии методов для суперкласса!
    Window currWind = getWindow();

    Sometimes this may be required and is solved for example as follows:
    new BaseInputConnection (txtView, false) .sendKeyEvemt (backPressedKeyEvent);

    I am sure there are other ways, but the code above helped me return to the previous window after an unsuccessful search.

    SQLite cache SQLite

    caches data. You just need to remember this during application development and check the wipe user data box (if you want to update the data). At one time, I spent several hours understanding why this is so, not knowing this feature.


    Inherit from ListActivity or not? In fact, the only difference is whether other elements and the layout itself are needed in the window design. If yes, then you don’t need anything to inherit, if not, then you don’t need to call the class and setContentView.
    You should also remember one important thing about lists. The list uses view elements repeatedly, so you need to work with it carefully. You can, for example, use the view methods: setTag (), getTag () in order to bind arbitrary identifiers. You should also carefully consider writing a custom adapter and using the convertView parameter in the getView () method, as I wrote above!

    Another problem when working with lists was the incorrect display of list items in ScrollView.
    Layout comprises such a piece: In this embodiment, the design elements of the list are truncated, and can be seen, not all (I think there is such issues on guglkode) solution to the problem was to set the size of the list by number of elements in it, the code is as follows: Dialogs


    android:cacheColorHint="#00000000" />


    //set ListView size by items count
    public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
    // pre-condition

    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) {
    View listItem = listAdapter.getView(i, null, listView);
    listItem.measure(0, 0);
    totalHeight += listItem.getMeasuredHeight();

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));

    When writing a custom dialog (inheriting the Dialog class), the difficulty arose: the buttons were easily found by findViewById () and worked correctly, but there was no EditText widget (the method returned null). As usual, LayoutInflater was used to search for the root element. The solution was simple - create a Dialog class, pass the desired layout and then call findViewById () from the dialog. And by the way, it was not possible to convey the application context as I did not try, because the dialogs are tied to the current activity. But I still suspect that this problem can be solved!

    Do not reinvent the wheel

    A lot of ready-made classes and applications are already in Android, and therefore it is better to first look carefully at the dock or google.

    Use LogCat

    Logging helps you quickly find an error during development (especially using your filters in Eclipse) and view the necessary output of activity, services, etc., therefore always use it. But logging needs to be removed from the release version (as Google says), although a bunch of standard services and applications on the device are still written to the log!

    SQLite Manager

    I used this plugin for Firefox 3.x to work with sqlite database. It is free, convenient, functional (you can write procedures, see table structures, data, execute queries, etc.). So I recommend to everyone who still does not know or wants to choose a similar tool, the very thing for development. Although a bunch of alternatives!

    Application size limit

    This is the funniest item. On the day or rather the hour of release to the market, we find out that the application cannot be more than 50MB, and ours weighs 79! Thank you Google for such a chip ... because of this I had to make a not-so-pleasant decision ...


    This is the window with recipes in the selected category:

    Screen with all categories of recipes:

    Screen of the selected recipe:

    And it looks like a window with timers:

    Conclusion I

    emphasize that mine recommendations can be disputed since I am not a guru in Android (this is my first application and part-time first post on Habré) and the platform often has several ways to solve one problem, but the tips I have reviewed work and it pleases! I support the call for the exchange of experience, which was already on Habré.

    Otherwise, the development process was approximately the same as in web applications: a data model is written, CRUD operations for this model, an interface, and the necessary functionality. The difficulties were due to ignorance of the Android platform and lack of experience in creating applications for mobile platforms.

    Comments and suggestions on the topic in private messages.
    Thanks for attention!

    UPD Now the application is also available in the free version:

    Also popular now: