Posts

Showing posts from March, 2013

Threading in Android

Image
A Thread is a sequence of instructions executed in order. Although each CPU can proc- ess only one instruction at a time, most operating systems are capable of handling multiple threads on multiple CPUs, or interleaving them on a single CPU. Different threads need different priorities, so the operating system determines how much time to give each one if they have to share a CPU. The Android operating system is based on Linux and as such is fully capable of running multiple threads at the same time. However, you need to be aware of how applications use threads in order to design your application properly. Single Thread By default, an Android application runs on a single thread. Single-threaded applications run all commands serially, meaning the next command is not completed until the pre- vious one is done. Another way of saying this is that each call is blocking . This single thread is also known as the UI thread because it's the thread that processes all the use...

View Flow for Android

Image
In a project I’m currently working on we had the need of scrolling through a bunch of views in a horizontal fashion. I wanted the ViewGroup to be backed up with an Adapter, pretty much like the ListView does it. In my case, the items were to be populated from an online data source. I did find a few different takes on a view switcher but none of them were backed with an Adapter. So I decided to base my work on one of them, but instead extend the AdapterView class in the Android SDK (instead of simply the ViewGroup ). If you’ve implemented a ListView you’ve probably already come across the Adapter concept. An Adapter in Android is more or less a collection of elements of some sort. The Adapter is capable of providing views for each of the elements when asked to. A Listview does, of course, not load a View for each of the elements in the Adapter at once. That would be completly irresponsible as it would eat up the memory in no-time. Instead it loads the view for each element ...