title: Koltin: Pass Context from inner class
body: <p>I want to make a toast in the foo method.
  I have already tried different accesses (see comments). What am I doing wrong?</p>
  <p>This didn't work:</p>
  <pre><code>class SettingsActivity : AppCompatActivity() {
      companion object{
          fun foo(context : Context){
              Toast.makeText(context, &quot;Bar&quot;, Toast.LENGTH_LONG).show()
          }
      }
      private fun createListener() {
  
          var listener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key -&gt;   
                  foo(this)
                  //foo(this.applicationContext)
                  //foo(this@SettingsActivity)
              }
      }
  }
  </code></pre>
  <p>Working Example:</p>
  <p>I could only call Foo if I passed a string instead of context and replaced the toast with a logging object. I called foo in the example with <code>&quot;foo(&quot;ttt&quot;)&quot;</code>:</p>
  <pre><code>    //this works:
      fun foo(context : String){
          Log.v(&quot;TTTTTT&quot;, &quot;QQQQQQQQQQQQ&quot;)
      }
  </code></pre>
  <p>There were no errors in the logcat.</p>
  <p>Solved: Add <code>lateinit var hi : SettingsActivity</code> in the companion object and fill it before calling foo. Then you can omit the context parameter.</p>