title: Android - How to pass a function to an Activity?
body: <p>I am attempting to create a Builder for an activity. The reason is because this activity can be started many different ways. I created a Builder class like this:</p>
  
  <pre><code>class ActivityBuilder {
  
      private var showToolBar = false
      private var postExecutable: (() -&gt; Unit)? = null
  
      fun showToolbar(boolean: Boolean) : ActivityBuilder {
          this.showToolBar = boolean
          return this
      }
  
      fun setPostExecutable(function: () -&gt; Unit) : ActivityBuilder {
          this.postExecute = function
          return this
      }
  
      fun start(context: Context){
          val intent = Intent(context, Activity::class.java)
          context.startActivity(intent)
      }
  }
  </code></pre>
  
  <p>The idea is to call something like this and have access to these fields inside of the activity.</p>
  
  <pre><code> ActivityBuilder().showToolbar(false).setPostExecutable { { doSomething() } }.start(this)
  </code></pre>
  
  <p>I guess I could also use a companion object and that would serve the same purpose.</p>
  
  <pre><code>companion object Builder {
  
      private var showToolBar = false
      private var postExecute: (() -&gt; Unit)? = null
  
      fun showToolbar(boolean: Boolean) : Builder {
          this.showToolBar = boolean
          return this
      }
  
      fun setPostExecutable(function: () -&gt; Unit) : Builder {
          this.postExecute = function
          return this
      }
  
      fun start(context: Context){
          val intent = Intent(context, AuthActivity::class.java)
          context.startActivity(intent)
      }
  }
  </code></pre>
  
  <p>The issue is coming mostly from the "postExecutable" field. I need to call the function at a certain point but it is not parcelable, so I cannot pass it through the intent when starting activity.</p>
  
  <p>If anyone has a solution, I appreciate it!</p>