hello there
I'm a newbie in android.
I'm tryin to develop a game checking user's knowledge. for every
question asked , the player has 20 secs to answer. otherwise he loses.
I'm trying to pause my activity when clicking menu, however i don't
know how to pause the timer thread.
In my menu i have 2 options( new game or quit).  so i need to pause
everything when clicking the menu and resuming when clicking it again.

PLEASE HELP.
Thank you

that's how i'm keeping track of time:


    public void timedOut()
               {                        //called when time limit is reached for 
input
                    timer.interrupt();                                  //stop 
the timer thread
                    lost = true;                                        
//player lost, so set lost variable
to true
                    input_text.setText("");                     //clear 
input_text area of
any text
                 Toast.makeText(getBaseContext(), "You took TOO LONG!",
Toast.LENGTH_SHORT).show();
                 Toast.LENGTH_SHORT).show();
                 disptext.setVisibility(4);             //remove text display 
area
                 endgame();
    }

    public class timerThread extends Thread {                   //times user 
input
        public int time = 0;                                                    
//keeps track of time in hundreds of
milliseconds
        public int timeLimit =200;                                              
//initial time limit (20 seconds)

        public void run() {
                time = 0;
                while(time < timeLimit) {                       //as long as 
time limit has not been
reached,
                        if (isInterrupted()) {return;}             //if 
interrupted
before sleep, we will know
                        time++;                                                 
//add another 200 ms to time
                        try {
                                        sleep(100);                             
        //and sleep for 200 ms
                                } catch (InterruptedException e) {
                                        return;                                 
        //leave run() if interrupted
                                }
                }

                handleTimer.post(timeUp);                       //when player 
input is too late,
pass timeUp to the handler
        }




that's how i'm using the menu:


    public boolean onCreateOptionsMenu(Menu menu) {

         super.onCreateOptionsMenu(menu);
             getMenuInflater().inflate(R.menu.menu, menu);
             playgame.getThread().onPause();


             return true;
        }



public boolean onOptionsItemSelected(MenuItem item) {
        super.onPause();
        playgame.getThread().onPause();
  switch (item.getItemId())
    {
        case R.id.quit:
                finish();
                return true;
        case R.id.new_game:
                newGame();
                return true;

    }
             return false;
}




@Override
protected void onPause() {
    super.onPause();
    SimonSays.getThread().onPause();
}




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to