State Capitals 1.0.2
I released State Capitals version 1.0.2 tonight. This is an Android flash-card app for U.S. State Capitals.
To find it, just go to the Android Market and search for “State Capitals”.
This release does not add any new features. Instead, I focused on:
- Improved performance
- Reduced memory allocation, resulting in less garbage collection
- Smoother animation
The animation is the biggest visible change. In the old version, a fling gesture moved to the previous or next card. My approach was:
- Use a standard Android animation to slide the activity to the left or right, depending on whether you were moving to the next or previous card
- At this point, you’d see a black screen. This is where I loaded the next bitmap, and the garbage collector generally ran
- Use another animation to slide the activity back onto the screen. (with the new bitmap)
If you’ve used the app, you also know I spin the card around using an animation. Every time onDraw(…) was called, I’d paint the card border, the state bitmap, and the text on top of the state. This made the code very inefficient.
The New Approach
In the new version, you can slide your finger on the screen, and the card moves with your finger. You also see the previous or next card directly adjacent to the current card.
I also generate a bitmap for the entire screen, and cache that bitmap. So when an animation occurs, I simply paint the cached bitmap.
Finally, I eliminated many memory allocations. For example:
- I only save your settings when onPause(…) occurs. Before, I was writing to preferences every time something changed, which resulted in large numbers of object allocations
- I eliminated several Lists and Maps, replacing them with simple arrays
- I reuse the same Bitmap and Canvas objects over and over
If you want to learn more, check out “Google I/O 2009 – Writing Real-Time Games for Android”.
My focus on reduced object allocation is a direct result of watching that video, and it made a huge improvement to my app.
Warning: Parameter 2 to wp_hide_post_Public::query_posts_join() expected to be a reference, value given in /home/stuffthathappens/public_html/blog/wp-includes/class-wp-hook.php on line 286