Skip to main content


Showing posts from May, 2012

avoid PendingIntent collision

Android always wants to challenge developers.

I was playing with Widget, RemoteViews and PendingIntent, everything worked nicely(at least seemed to be) until I tried to add two buttons in my widget.

The code always get the same pengingIntent! I tried to set actions, use different viable, no help. Then I figured out Android always try to merge similar PendingIntent, that's how FLAG_CANCEL_CURRENT and related flags can be implemented. now the question is: how can we prevent Android from doing this?

The answer is surprisingly simple yet hard to figure out if you trust Android documentation. Someone pointed out in stackoverflow, The solution is passing a different requestCode in getBroadcast public static PendingIntent getBroadcast (Context context, int requestCode, Intent intent, int flags)

But, hey, Android documentation says requestCode is not used!

requestCodePrivate request code for the sender (currently not used).

How to make Android emulator fast

Android emulator is much slower than iPhone simulator. Because it is emulating arm on top of x86, while iPhone simulator just runs native x86 code. But the default settings for Android emulator is so slow that is barely useable. Luckly we can change some settings to make it reasonable fast.

Open "Android SDK and AVD Manager", create a new AVD or edit an existing one. Click "New..." hardware to add a new hardware called "Device Ram Size"

Change the value to 1024.
Save the changes and launch the emulator.