title: Where to call finish()?
body: <p>I am saving an event. When I click on save I want to check if title is not null and start time equals end time and dose event overlap and then save the event.</p>
  
  <p>I have a boolean variable to check if edit mode is true. If it is true I want to update the existing event.</p>
  
  <p>Now I tried to do this but when I am saving the event I want to check all these scenario and show the snackbar and then finish the activity. </p>
  
  <p>1) But now the activity get finishes as soon as I click on save. </p>
  
  <p>2) Also When I want to update it shows event exists. </p>
  
  <p>What's wrong here?</p>
  
  <pre><code>  save.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              eventTitle = title.getText().toString();
              location = mAutocompleteView.getText().toString();
  
  
              if (eventTitle.length() == 0) {
  
                  showAlert("Title can not be empty.");
  
              }
              else if (startTime.equals(endTime)) {
                  showAlert("End Time can not be same as Start Time.");
              }
  
              else if (db.doesEventOverlap(startTime,endTime,dayOfWeek)) {
  
                 showAlert("Event Exists");
  
              }
  
              else {
  
                  if (editMode) {
  
                  eventData.setTitle(title.getText().toString());
                  eventData.setFromDate(fromDate);
                  eventData.setToDate(toDate);
                  eventData.setDayOfWeek(selectDay.getText().toString());
                  eventData.setLocation(mAutocompleteView.getText().toString());
                  eventData.setNotificationTime(notificationTime);
  
                      db.updateEvent(eventData);
  
                      Toast.makeText(getApplicationContext(),"Event Updated",Toast.LENGTH_SHORT).show();
                  }
  
                 else {
                          db.addEvent(new EventData(eventTitle, startTime, endTime, dayOfWeek, location, notificationTime, mColor));
                          showAlert("Event Added.");
                  }
  
                  setResult(RESULT_OK, i);
                  finish();
              }
          }
      });
  </code></pre>
  
  <p>dose event overlap function :</p>
  
  <pre><code>     boolean doesEventOverlap(String startTime, String endTime, String day) {
      String selectQuery = "SELECT COUNT(*) FROM " + TABLE + " WHERE " + KEY_DAY_OF_WEEK + " = '" + day + "'" + " AND "
  
              + "(" + KEY_FROM_DATE + " &lt; '" + startTime
              + "' AND '" + startTime + "' &lt; " + KEY_TO_DATE + ") OR "
  
              + " (" + KEY_FROM_DATE + " &lt; '" + endTime
              + "' AND '" + endTime + "' &lt; " + KEY_TO_DATE + ") OR "
  
              + " (" + KEY_FROM_DATE + " &lt; '" + startTime
              + "' AND '" + endTime + "' &lt; " + KEY_TO_DATE + ") OR "
  
              + " ('" + startTime + "' &lt; " + KEY_FROM_DATE
              + " AND " + KEY_TO_DATE + " &lt; '" + endTime + "')";
  
  
      SQLiteDatabase db = this.getWritableDatabase();
      Cursor cursor = db.rawQuery(selectQuery, null);
  
      if (cursor.moveToFirst()) {
          do {
              EventData event = new EventData();
              return cursor.getInt(0) &gt; 0;
          } while (cursor.moveToNext());
      }
      return false;
  }
  </code></pre>
  
  <p>create table</p>
  
  <pre><code>  public void createTable(SQLiteDatabase db){
      String CREATE_EVENTS_TABLE = "CREATE TABLE " + TABLE_EVENTS + "("
              + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
              + KEY_TITLE + " TEXT,"
              + KEY_FROM_DATE + " DATE,"
              + KEY_TO_DATE + " DATE,"
              + KEY_DAY_OF_WEEK + " TEXT,"
              + KEY_LOCATION + " TEXT,"
              + KEY_NOTIFICATION_TIME + " DATE,"
              + KEY_COLOR + " TEXT" + ")";
  
      db.execSQL(CREATE_EVENTS_TABLE);
  }
  </code></pre>
  
  <p>Thank you..</p>
  
  <p>Edit :</p>
  
  <p>show alert method for snack bar.</p>
  
  <pre><code> public void showAlert(String alert){
  
      Snackbar.make(parentLayout, alert, Snackbar.LENGTH_LONG).show(); // Don’t forget to show!
  
      Snackbar.setCallback(new Snackbar.Callback() {
          @Override
          public void onDismissed(Snackbar snackbar, int event) {
              super.onDismissed(snackbar, event);
              finish();
          }
  
          @Override
          public void onShown(Snackbar snackbar) {
              super.onShown(snackbar);
          }
      }
  }
  </code></pre>