Home Development for Android Revisit old Android 4.0 projects. Part Two

Revisit old Android 4.0 projects. Part Two

by admin

Most recently, I posted topic which talked about code that worked in Android 2.3, but stopped working in Android 4.0. A few people wrote to me personally, thanked me for the information and asked me to continue this kind of publication. This time we’ll talk about ActionBar. One user had a problem with a code that worked on Android 3.0, but stopped working on Android 4.0 again.

A little digression – You wicked, I’ll leave you.

About 15 years ago, when I started to learn programming on my own and joined the Internet at the same time, I noticed an amazing thing. When I, being a beginner, asked a question on a Russian-language forum, I received silence in response or received an advice to study the source code and not to get in the way. When I posed the same question on bourgeois forums, and even in poor English (at school I studied German), I received detailed answers. Since then, virtually nothing has changed. I have long since given up on our forums and prefer to communicate only "there". Surely, many have noticed how strikingly different the comments on blogs. They have : nice tutorial, thanks for post, excelent article. With us: why another bicycle, your horizon is crooked, colors are grotesque, vindecapets, etc.
I personally know several of the "exes" who blogged in two languages, English and Russian, and then left only the English part. Do you understand why?
It was the same with my previous post. Here are the typical statements: execute, the harsh Chelyabinsk programmers, etc. Somehow it was a coincidence that on foreign resources a few times I came across similar questions, but no one suggested to shoot for wrong code, but simply explained why you can not do so. One example is. http://stackoverflow.com/questions/9442527/networkonmainthreadexception-when-reading-from-web And in general only on this resource on request NetworkOnMainThreadException returned 90 results. And no one swears. As they say, feel the difference. It’s our mentality.

New problem – icon does not work in ActionBar

This problem was shared by one of the registered users my site The point was the following – The application icon can work as a navigation element and play the role of the Home button, like in particular the Hubra logo on the site. This is very useful in some cases, when the application consists of several screens and you can "poke" at the system application icon to quickly return. The example is described in the documentation and worked fine on a tablet running Android 3.0, but on Android 4.0 it suddenly stopped working.
In principle the answer on the Internet was found quickly, in fact, even in the documentation you can find a solution. However, apparently the developer was just tired or had a black eye, but he did not find it. The solution was very simple. In order to make an application icon work as a navigation element, the following method should be explicitly mentioned setHomeButtonEnabled()

 protected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.two);ActionBar bar = getActionBar();bar.setHomeButtonEnabled(true);}

It turns out that in Android 3.0 the icon was enabled as the default navigation button, but in Android 4.0 it is not.
By the way, I found an interesting thing about this button. The system allows you to add an extra arrow to the left of the application icon using the bar.setDisplayHomeAsUpEnabled(true);
Revisit old Android 4.0 projects. Part Two
So, if you call this method, you don’t need to call the previous method setHomeButtonEnabled(), everything works as it is.
Have fun with your programming!

You may also like