カウントダウンタイマーを作成しましたが、ブール値がtrueの場合に開始されます。タイマーが実行されているかどうかを検出すると、さらに良い結果が得られます。それを行う方法はありますか?
次の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();
}
};