title: Using EventBus to finish an Activity from Base Activity?
body: <p>Working on an existing project, I found this rather uncommon piece of implementation (to me at least). Since I am not in contact with the previous developer who already left, and before I dismiss this as a case of simply copy and pasting code from another part of our codebase, I would like to ask the SO community about this.</p>
  
  <p>Here's your everyday activity that extends BaseActivity, and the implementation:</p>
  
  <pre><code>class SomeActivity : BaseActivity(R.layout.some_activity) {
      ...
      private fun close() {
          if(backToMain)
              finish()
          } 
          else
              goToMain(this)
      }
  
      companion object {
          fun goToMain(activity: AppCompatActivity) {
              val intent = Intent(activity, MainActivity::class.java)
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
              activity.startActivity(intent)
              EventBus.getDefault().post(Event(Event.Type.ActivityFinish))
          }
      }
      ...
  }
  </code></pre>
  
  <p>In BaseActivity.kt, there's a subscription to the event which calls finish().</p>
  
  <pre><code>@Subscribe override fun onEvent(event: Event) {
      when (event.type) {
          Event.Type.ActivityFinish -&gt; super.finish()
          else -&gt; {}
      }
  }
  </code></pre>
  
  <p>Now, <strong>why would anyone use EventBus to call</strong> <code>Activity.finish()</code> from the extended BaseActivity, instead of just calling it then and there (in the above SignActivity)? <strong>Even if SomeActivity were actually a fragment</strong>, you could simply call <code>getActivity.finish()</code>.</p>
  
  <p>*With regards to the intent flags, you could also use <a href="https://developer.android.com/reference/android/app/Activity.html#finishAffinity()" rel="nofollow noreferrer"><code>Activity.finishAffinity()</code></a> to finish all activities in the back stack if your min SDK is 16.</p>
  
  <p>Thanks in advance for feeding my curiosity. :D</p>