0

I am having a class that implements Runnable and inside this class is implemented the gameloop of my game. In few words, I have a stopwatch and I want at a specific time to show a message with options to the user. At this point the user either is winner either has to try again. I know that I cannot start a new activity inside the thread. So, I have the following options:

  1. Use of a Handler and a Looper to start my new activity
  2. Kill the thread somehow and start my new activity
  3. Stop the thread and go to the new activity

Is there any other way? I would like to know the best way to do this.

All comments and responses will be helpful for me, thanks.

4

2 回答 2

1

I would recommend using a handler. Im not familier with the looper class but i just simply passed a Handler object when creating threads from the uiThread. then sent messages to the handler from the thread and doing the appropriate ui stuff by overwriting the handlemessage in the handler. So my suggestion would be to use an anonymous innner class for the handler (in the ui thread) and then pass that to the runnable class.

于 2013-06-23T17:08:24.233 回答
0

I know that I cannot start a new activity inside the thread.

You can start a new Activity inside a UI thread.

To do so, you can use runOnUiThread(Runnable action) method. For example, if you are in Activity, just do:

runOnUiThread(new Runnable() 
{
    public void run() 
    {
        // start another Activity here
    }
});
于 2013-06-23T17:07:50.903 回答