Android Activity transition slide in/out animation

This is a very common effect, however the Android framework only provides the slide in animation. This is how I implement all the sliding transition animation. There’s in total 4 XMLs to define the animation, and with the use of overridePendingTransition() in appropriate location you can implement this easily.

pull_in_left.xml  Continue reading “Android Activity transition slide in/out animation”

Inspect the view hierarchy (layout) of any Android app

Ever wondering how a particular app structure their hierarchy of views? With the latest Android SDK(I’m using 21.01 currently) and Eclipse ADT plugin, you can finally do that!

1. Connect your phone, Open the app you are curious about. Switch to the DDMS perspective, See the little button over there? click on it.insepct_view_hierarchy_1

2. The following screen will appear, you can now browse the view hierarchy just like a DOM tree which Web developers are familiar with.

insepct_view_hierarchy_2

What is does is basically dump a snapshot of the view in the current screen to the IDE. There’s quite a lot of information you can see in the “Node Detail” section, but you probably cannot reconstruct a layout XML in your own code by these info because It doesn’t show you some attributes like layout_width, layout_height, layout_weight etc. But it definitely tells you what types of views you need to build a particular layout.

Android: Can’t establish a reliable data connection to the server

Few days ago I saw this strange error message when I try to login my Google account on the HTC Desire (my previous phone):

Can’t establish a reliable data connection to the server

Since I cannot login to google, I cannot use the Play Store, Gmail, Youtube etc. My phone was connected to the home WiFi and the internet is definitely working.

I was thinking maybe this phone is already old and maybe Google changed something in their Authentication API. When I was about to give up after trying for about 10 times, I realize something Continue reading “Android: Can’t establish a reliable data connection to the server”

Why Learning Android could improve your programming skills

Android is probably the most popular mobile operating system, a lot of programmers join the Android club to be an Android developer and turn their ideas into great apps. While some of you may not be interested in making a mobile app, but I would say you should give it a try. In this article I’ll try to convince you that you can improve your programming skills by studying the Android framework.

It’s simple

By simple, I don’t mean programming in Android is easy. The Google Android team has made it very easy for beginners to get started, just fire up the Eclipse IDE and load the examples and you have your first Android app. Through Android you’ll learn how to organize an app that is so simple to understand, write and deploy. You could apply this in organizing your web application. There’s a lot of good engineering practice in the Android framework. Of course, programming is never easy, if you feel that what you’re doing is easy, you maybe not making something useful!

It’s well documented

Learning Android is a joy. Continue reading “Why Learning Android could improve your programming skills”

Patterns for running Asynchronous code in Android (Part 1)

An important technique in Android Programming is to make potentially long task run asynchronously in your app, avoid blocking the UI thread, so your app feels more responsive. For example, downloading a file from the Internet, loading a media file from the external storage or applying a filter on an image bitmap etc. I will show you how to implement with AsyncTask, simple java threads and java Executor in Part 1.

Let’s say I want to load a bitmap from the internet, and set it to an ImageView , this might be what you’d write at first:

The Java way: simple Threads

You can implement it just like any other Java programs, define a Thread that does the job, and run it. Every Java programmer knows how to do that. Remember that if you want to modify the UI, you need to use runOnUiThread()

Continue reading “Patterns for running Asynchronous code in Android (Part 1)”

[Android] Using LruCache to cache Bitmaps and limit memory usage

Bitmaps are very bulk objects, loading them from the Internet or local storage could be expensive and “choke” the UI. You want to  keep them in memory so that they could be loaded instantly, however you also want to discard them as soon as they are not useful. Here comes the LruCache.

What is LruCache?

LruCache is a util introduced in API 12, which is an implementaion of the Least Recently Used cache. In short, that is a caching strategy which the “oldest” entries are discarded when overflow occur. It is very useful to cache Bitmaps. The default implementation allows you to limits the number of items in the cache. Here’s how to slightly modify the LruCache to limit the memory usage of the cache.

How to use it?

Well, actually it act just like a HashMap. Continue reading “[Android] Using LruCache to cache Bitmaps and limit memory usage”

iOS 6 : closed source OS disaster

I believed that a lot of iPhone, iPad and iPod touch owners are excited about iOS 6, which is released a while ago, and already made the upgrade. There are couple of cool new features, however, some people think it is a mess. The most obvious example is the Maps app, which the good old Google Maps is replaced with a half-baked Apple Maps. You can choose not to upgrade, but for those upgraded, you have no choice but wait for the release of Google Maps App.  This is an example of the drawbacks of having closed source OS and closed App ecosystem.

A Closed ecosystem

iOS is a closed source OS, that doesn’t bother much people as long as it works. MS Windows is also closed source, but it just works. The problem of iOS is that it also comes with a tightly controlled AppStore ecosystem which distribution of Apps need to be approved by Apple. This might have proven to have a lot of advantages, users are happy because of higher quality of software, developers are happy because they can earn a living and of course Apple is happy with all that income by selling apps. However, the major problem is that developers and users cannot publish software freely on the platform and modify/customize the iOS in the way they want.

Continue reading “iOS 6 : closed source OS disaster”