title: Is there a way to pass a function reference between activities?
body: <p>is there a way of bundling function references in Kotlin and Android so that the functions can be called from other fragments? 
  For instance, my fragment factory method looks like this: </p>
  
  <pre><code>    fun newInstance(tryAgainFunction: () -&gt; Unit): TimeOutHandlerFragment {
          val fragment = TimeOutHandlerFragment()
          val bundle = Bundle()
  
          return fragment
      }
  </code></pre>
  
  <p>I want to be able to save my tryAgainFunction in the bundle for further retrieval. </p>
  
  <p>Thanks a lot!</p>
  
  <p><strong>Edit</strong></p>
  
  <p>In the end, the most suitable solution was using hotkey's answer and then in onViewCreated I initializing a listener with the passed function. The complete code is as follows:</p>
  
  <pre><code>companion object {
      val CALLBACK_FUNCTION: String = "CALLBACK_FUNCTION"
  
      fun newInstance(tryAgainFunction: () -&gt; Unit): TimeOutHandlerFragment {
          val fragment = TimeOutHandlerFragment()
          val bundle = Bundle()
          bundle.putSerializable(CALLBACK_FUNCTION, tryAgainFunction as Serializable)
          fragment.arguments = bundle
          return fragment
      }
  }
  
  override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
      super.onViewCreated(view, savedInstanceState)
      try {
          val callback: () -&gt; Unit = arguments.getSerializable(CALLBACK_FUNCTION) as () -&gt; Unit
          btnTryAgain.setOnClickListener { callback.invoke() }
      } catch (ex: Exception) {
          // callback has a wrong format
          ex.printStackTrace()
      }
  }
  </code></pre>
  
  <p>Thanks to everyone for your help!</p>