Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Multiple Game Threads

+12 votes
When running my app I often get an alert stating "Skipped 41 frames!  The application may be doing too much work on its main thread."  Since both in the cannon game and the recommended code to begin with the app is set up with one thread, i'm hesitant to attempt to add another thread.

Is adding another thread worth it/possible for a simple game app or should I just continue overloading the given game thread?
asked Mar 29, 2015 in Spring 2015 by Reed Kottke (100 points)

1 Answer

+2 votes
Best answer

Actually, the cannon game & starter code both use at least *two* threads -- the default GUI thread, and game loop thread that they create/run.

I am not sure whether an additional thread is going to be helpful for you.  I *doubt* that you want to explicitly create another thread.  Some possibilities:

a) The emulator is just slow (especially on older hardware).  Try running it on a physical device, and see if it runs smoothly.  You might also try creating an emulator (like small jelly bean) that has a lower-resolution screen, in case the high-res graphics are part of the problem.

b) you are doing something slow or resource intensive (maybe loading images?) on the main thread, which should be offloaded into a background thread.  You might consider using an AsyncTask for this:  see http://developer.android.com/training/articles/perf-anr.html

answered Mar 30, 2015 by Forrest Stonedahl (3,438 points)
selected May 20, 2015 by Reed Kottke