I created a countdowntimer and it starts now if a boolean is true, what would be better if I detect if the timer is running. Is there a way to do that?
I created the following class with the following countdowntimer:
public class GameActivity
{
int GameTime = 120;
long GameTimeLeft = GameTime;
long GameMillis;
/** Called when the activity is first created. */
@Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.gamemap );
myupdater = new Handler();
GameMemory = new PreferenceHandler(this);
GameTimeLeft = GameMemory.getMinutesLeft();
GameMillis = ( GameTimeLeft * 60000 );
if ( GameMemory.getTimerSetting() )
{
Log.d( "StartTimer", "Minutes Set " + ( GameMillis / 60000 ) );
GameTimeLeftCounter.start();
GameMemory.setTimerSetting( false );
}
}
CountDownTimer GameTimeLeftCounter = new CountDownTimer( GameMillis, 60000 )
{
public void onTick( long millisUntilFinished )
{
GameTimeLeft = millisUntilFinished / 1000 / 60;
Log.d( "GameTimeLeftCounter", "Time Left: " + GameTimeLeft );
GameMemory.setMinutesLeft( GameTimeLeft );
}
public void onFinish()
{
//GAME OVER TIMER FINISHED
Intent gameover = new Intent( BarcelonaTriviaGame.this, GameOver.class );
gameover.setFlags( Intent.FLAG_ACTIVITY_NO_ANIMATION );
Log.d( "TimerFinished", "Finished" );
startActivity( gameover );
finish();
}
};