@Override
 protected void onDestroy() {
   if (mCountDownView.isCountingDown()) {
     mCountDownView.stopCountDown();
   }
   super.onDestroy();
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.sample_menu:
       if (mStartCountDownFlag) {
         Intent intent = new Intent(this, SampleActivity.class);
         intent.putExtra(Constants.EXTRA_KEY_IMAGE_FILENAME, mImageFile.getName());
         intent.putExtra(Constants.EXTRA_KEY_TIME_LIMIT, mCountDownView.getRemainingTime());
         startActivity(intent);
       }
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
  @Override
  public void onFinish() {
    mCountDownView.stopCountDown();

    final int score = (int) mCountDownView.getElapsedTime();

    final ProgressDialog progress = createAndShowProgressDialog(R.string.play__progress_sending);

    Handler mHandler = new Handler();
    Runnable mRunnable =
        new Runnable() {
          @Override
          public void run() {

            String stageId = mStageId;
            Context context = getApplicationContext();
            String playerId = PreferenceHelper.loadPlayerId(context);
            String nickname = PreferenceHelper.loadNickname(context);

            try {
              // --------------------------------
              //  Find Own FirstComeRanking
              // --------------------------------
              ABQuery queryAllFirstComeRanking =
                  FirstComeRanking.query()
                      .where(FirstComeRanking.Field.STAGE_ID)
                      .equalsTo(stageId)
                      .and(FirstComeRanking.Field.PLAYER_ID)
                      .equalsTo(playerId);
              ABResult<List<FirstComeRanking>> resultAllFirstComeRanking =
                  AB.DBService.findSynchronouslyWithQuery(queryAllFirstComeRanking);
              List<FirstComeRanking> firstComeRankingList = resultAllFirstComeRanking.getData();
              if (firstComeRankingList.size() == 0) {
                // --------------------------------
                //  Increment Sequence
                // --------------------------------
                FirstComeRankingSequence sequence = new FirstComeRankingSequence();
                long rank = sequence.getNextValueSynchronously();
                // --------------------------------
                //  Create FirstComeRanking
                // --------------------------------
                FirstComeRanking ranking = new FirstComeRanking();
                ranking.setStageID(stageId);
                ranking.setPlayerID(playerId);
                ranking.setNickname(nickname);
                ranking.setScore(score);
                ranking.setRank((int) rank);
                ranking.saveSynchronously();
              }

              // --------------------------------
              //  Find Own TimeRaking
              // --------------------------------
              ABQuery queryAllTimeRanking =
                  TimeRanking.query()
                      .where(TimeRanking.Field.STAGE_ID)
                      .equalsTo(stageId)
                      .and(TimeRanking.Field.PLAYER_ID)
                      .equalsTo(playerId);
              ABResult<List<TimeRanking>> resultAllTimeRanking =
                  AB.DBService.findSynchronouslyWithQuery(queryAllTimeRanking);
              List<TimeRanking> timeRankingList = resultAllTimeRanking.getData();
              if (timeRankingList.size() > 0) {
                TimeRanking ownTimeRanking = timeRankingList.get(0);
                if (score < ownTimeRanking.getScore()) { // NOTE: スコアが小さい方がより高得点
                  // --------------------------------
                  //  Update TimeRanking
                  // --------------------------------
                  ownTimeRanking.setScore(score);
                  ownTimeRanking.saveSynchronously();
                }
              } else {
                // --------------------------------
                //  Create TimeRanking
                // --------------------------------
                TimeRanking ranking = new TimeRanking();
                ranking.setStageID(stageId);
                ranking.setPlayerID(playerId);
                ranking.setNickname(nickname);
                ranking.setScore(score);
                ranking.saveSynchronously();
              }

              progress.dismiss();

              Intent intent = new Intent(PlayActivity.this, PlayResultActivity.class);
              intent.putExtra(Constants.EXTRA_KEY_STAGE_ID, stageId);
              intent.putExtra(Constants.EXTRA_KEY_SCORE, mCountDownView.getElapsedTime());
              startActivity(intent);
              finish();

            } catch (ABException e) {
              progress.dismiss();
              showError(PlayActivity.this, e);
              e.printStackTrace();
            }
          }
        };
    mHandler.postDelayed(mRunnable, 2000);
  }