On Wed, Apr 24, 2013 at 10:26 AM, bob <b...@coolfone.comze.com> wrote:

> So, basically, the drawing thread was looping thru some enemy ships trying
> to draw them.
>
> Meanwhile, someone pressed the reset button on the game (an onTouchEvent),
> and the enemy ship LinkedList got cleared.  This clearing occurred while
> the drawing thread was looping thru them.  Thus an
> IndexOutOfBoundsException occurred.
>
> Anyhow, I guess my question is...  how would the professional Android
> developer have prevented this?
>

This is a bit of an advanced multi-threading question that is not specific
to Android. In short, you need to synchronize any resource that is being
accessed by multiple threads, in this case your list. There are many
strategies and facilities for doing so, some built right into Java (see the
synchronized keyword). You will have to do some research on multi-threaded
resource use.

-------------------------------------------------------------------------------------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to