Android is a message driven application framework. The message looper is the thread that reads messages queued for your application and calls the methods in your application based on the message context. By calling sleep, you effectively put your entire application to sleep for 10 seconds because it can't respond to any external messages coming from the framework. You never want to call sleep from any function that is called directly or indirectly by the framework.
On Jan 19, 2:29 am, steve_macleod <[email protected]> wrote: > Hi Dave, > First - thanks for the reply. > > Maybe im missing something here, but what is the app's "message > looper"? > > I am creating the thread with the following line: > > mPacManThread = new PacManThread(mSurfaceHolder, context, null); > > The PacManThread takes the following arguments (used the LunarLander > thread as a reference): > > PacManThread(SurfaceHolder surfaceHolder, Context context, Handler > handler) > > I have left the handler null. I presume the message looper concept has > something to do with this handler. I didn't understand its purpose at > the time, so I left it null. > I have read the class description, but still in the dark as far as its > purpose. > > So, I guess my question is, what is a message looper and what > relationship does it have with the handler argument? > > many thanks, > > On Jan 17, 8:09 pm, Dave Sparks <[email protected]> wrote: > > > This will put your app's message looper to sleep for 10 seconds, which > > is probably not what you want. As an alternative, you can send > > yourself a delayed message, or you can have your animation thread read > > the system time when it starts up and exit after the 10 seconds has > > expired. > > > On Jan 17, 2:55 am, steve_macleod <[email protected]> wrote: > > > > Hi, > > > I am writing an application to get a grip of basic sprite animation. I > > > have a surfaceCreated method which looks like this: > > > > public void surfaceCreated(SurfaceHolder holder) { > > > mPacManThread.setRunning(true); > > > mPacManThread.start(); > > > //this thread will wait for 10 seconds, and then kill the > > > mPacManThread thread > > > > try { > > > Thread.sleep(10000); > > > mPacManThread.setRunning(false); > > > Log.d("THREAD STOPPED","The animation thread has > > > been stopped, as > > > 10 seconds has elapsed."); > > > > } catch (InterruptedException e) { > > > // TODO Auto-generated catch block > > > e.printStackTrace(); > > > } > > > > } > > > > The intention is to start the thread which manages the user input and > > > animation, and make the main thread (that is the thread that started > > > the view) sleep for 10 seconds, before stopping the animation loop. > > > > My understanding is that the Thread.sleep(10000) will sleep the thread > > > from which the request originated (ie the main thread) for 10 seconds. > > > > However, it looks like the Thread.sleep() is actually working on the > > > animation (mPacManThread) instead. Am I missing something fundamental > > > here? > > > > Thanks,- Hide quoted text - > > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---

