Home Tutorials Hands on Threading with Android - part 1
Threading with Android - part 1
Wednesday, 17 September 2008 00:00
Article Index
Threading with Android - part 1
In Parallel
Source
All Pages

Spider in webMobile phones have always been good at multi-tasking. Even the basic early models had to simultaneously listen for calls, monitor the signal strength, update their displays and so on. Traditionally all this was handled at a low level using such languages as C or C++. Java has had multi-threading, the term given to this miracle of doing many things at once, from the start. Android, of course, implements it the standard way but also has a trick or two up its sleeve.

Tutorial: Threading 1 Skill: Medium Market install Download source

Here's an application to illustrate basic multi-threading by drawing counters on the screen in response to touch events, whilst a background process updates the numbers shown.

 

 

To keep the code simple all the app does is keep increasing a background counter whilst listening for new finger touch events. When it gets one, the screen is redrawn to show it, and the values inside any existing ones are updated from this counter. So, each time you press the screen all the numbers go up. You don't see the numbers spinning up continuously (thats in the next tutorial), but its clear theres more than one job going on here at once.

Heres how it looks when run:

 

     



 

Add comment


Security code
Refresh

Copyright © 2012 Android Academy. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.
 
Glossary
We have 38 guests online