Frequent Problems Raised in Android Programming

This post lists some problems appears frequently during Android developing.

##1. adb cannot run, adb server is out of date

Sometimes, when you want to installed your app on your smart phone with Eclipse running. It seems your computer has not detect your phone.

This is because there are some alternative Android USB detectors are running on port 5037. Such as tencent’s tadb.exe.

You will have this error message when you run adb start-server:

C:\Users\xxxx>adb start-server
adb server is out of date.  killing...
ADB server didn't ACK
* failed to start daemon *

We can use this snip to check which process is occupy the port tcp:5037

C:\Users\xxxxxx>netstat -ano | findstr "5037"
TCP    |  |       | LISTENING   | 4236 
TCP    |  | | ESTABLISHED | 4236 
TCP    | |  | ESTABLISHED | 3840 

Just kill the process 4236 then you will run adb.exe successfully.

##2. Animation run twice in listview

This is a programming mistake.

Once, I wanted to add a fade_in effect while a image is loading in the ListView. It’s easy to do so, just adding a fade_in animation to the ImageView.

photoToLoad.imageView.startAnimation(myFadeInAnimation); //Set animation to your ImageView

FadeIn Animation

But when I did so at the first time, the animation run twice for one ImageView. The 1st time is when the image’s top boundary shown up on screen; the 2nd time is when the image’s bottom bundary shown up on screen. It’s wired, right?

This is because the same animation was called again by the next ImageView. So, the 2nd time of that animation was actually caused by the next Image’s top boundary.

Why this happened? Finally, we found I had made a mistake on set the myFadeInAnimation variable as a shared one in our ImageLoader class. So, the same myFadeInAnimation will be called by different imageView.startAnimation() function. It happened to be twice was because our images are too big that one screen could only hold two such images at the same time.

Here I should create a new Animation every time when I want to add it to an ImageView.

Animation myFadeInAnimation = new AlphaAnimation(0, 1);
photoToLoad.imageView.startAnimation(myFadeInAnimation); //Set animation to your ImageView

Thanks for @Binzhe had taken a lot of time and finally figured out this foolish mistake I had made.

But actually, this is not a simlpe mistake one would make. On another words, this kind of mistakes is common in Android developing. We should take care that for many resources in Android, like Bitmap and Animation, they are designed for reusable.

For example, if you changed a Bitmap in one activity with adding opacity on it, this change will remain on the Bitmap. So the next time you want to use this Bitmap, it will always have that opacity.

I found even a Color resource has this kind of problem. I will figure it out later on.