title: Android Kotlin call a function in other activity
body: <p>I call a function of MainActivity in other Activity, the app shut down and show the error as below, please help to solve this issue. </p>
  
  <p>MainActivity function:</p>
  
  <pre><code>fun checkInternet():Boolean {
      val cm = baseContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
      val networkInfo = cm.activeNetworkInfo
      if (networkInfo != null &amp;&amp; networkInfo.isConnected) {
  
          alertPopUp("internet ok", "")
          return true
      }
      else {
          val title = getString(R.string.No_Internet)
          val message = getString(R.string.need_internet_for_service)
          alertPopUp(title, message)
  
          return false
      }
  
  }
  </code></pre>
  
  <p>Call this function in other activity:</p>
  
  <pre><code>var internetStatus:Boolean = MainActivity().checkInternet()
  </code></pre>
  
  <p>Error Message:</p>
  
  <blockquote>
    <p>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
        at com.gph.qpon.MainActivity.checkInternet(MainActivity.kt:148)
        at com.gph.qpon.qponClickedActivity.onCreate(qponClickedActivity.kt:32)</p>
  </blockquote>