title: Android Kotlin cancel callback
body: <p>still very new to Kotlin, i'm trying not to call my callback if my activity is null. 
  Let me explain, i have my DataManager that perform async work on some data: </p>
  
  <pre><code>fun performWork(callback: ((param1: T, param2) -&gt; Unit)?) { 
     // ... async work with data... 
     // Work is finished, let's call the callback :) 
     // as the callback is optional: 
     callback?.invoke(param1, param2)
  }
  </code></pre>
  
  <p>So i call my DataManager into my MainActivity: </p>
  
  <pre><code>DataManager.performWork(callback = { param1, param2 -&gt; 
    // update the UI now that the work is done. 
  }
  </code></pre>
  
  <p>What i want to do is not to call the callback if the callback is null (which means activity is null, or not on screen anymore...) </p>
  
  <p>So in my activity i declare an optional var: </p>
  
  <pre><code>var myCallback: ((params1: T, params2: T) -&gt; Unit)? = null
  </code></pre>
  
  <p>Then i have a function: </p>
  
  <pre><code>  var callbackMain: ((params1: T, params2: T) -&gt; Unit)? = fun (params1: T, params2: T) {
  
          print("ok")
  
      }
  </code></pre>
  
  <p>Then when i call my DataManager: </p>
  
  <pre><code>    mainCallback = this.callbackMain
      DataManager.performWork(mainCallback)
      mainCallback = null
  </code></pre>
  
  <p>So the async work is called... and the DataManager enter the callback because mainCallback is not null !!! I think its value is callbackMain. 
  Is there anyway i can make my callback nullable ? So it won't be called, and that my DataManager does not know the activity ? </p>
  
  <p>Thank you very much for any help. </p>