我创建了一个倒数计时器,如果布尔值为真,它现在开始,如果我检测到计时器是否正在运行,那会更好。有没有办法做到这一点?
我使用以下倒数计时器创建了以下类:
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();
}
};