title: How do I initialize a VideoView globally? (outside of the onCreate) Kotlin
body: <p>I'm trying to create a video background in my sign in/login activity (similar to Spotify and other apps). I followed this video, <a href="https://www.youtube.com/watch?v=WLwQ3SJjWfY" rel="nofollow noreferrer">https://www.youtube.com/watch?v=WLwQ3SJjWfY</a></p>
  
  <p>but I had to initialize my video background (VideoView) within my onCreate, because I couldn't figure out how to do declare it globally.</p>
  
  <p>Therefore my onPause and onDestroy methods can't access it.</p>
  
  <p>I can declare it certain ways inside my onCreate but once I do it globally I get an initiation error.</p>
  
  <p>This is the way I'm doing it in my onCreate and it works fine
      var videoBG = findViewById(R.id.videoView)</p>
  
  <p>I've tried to do these globally:</p>
  
  <pre><code>var videoBGGlobal:VideoView
  var videoBGGlobal = VideoView(this)
  var videoBGGlobal: VideoView = VideoView(this)
  var videoBGGlobal: VideoView? = VideoView(this)
  var videoBGGlobal: VideoView = null as VideoView
  var videoBGGlobal = null //and then tried to assign videoBGGlobal = 
  //videoBG within the onCreate but it says VideoView isn't type Nothing?
  </code></pre>
  
  <p>and I've tried more but I forgot the rest.</p>
  
  <pre><code>package ...
  imports ...
  
  class MainActivity {
  
  //Global variables
  var videoBGGlobal: VideoView = VideoView(this) //this just doesn't
  var mMediaPlayer: MediaPlayer? = MediaPlayer() //this works
  var mCurrentVideoPosition: Int? = 0 //this works
  
  override fun onCreate() {
       var videoBG = findViewById&lt;VideoView&gt;(R.id.videoView) //here it //works
       }
   override fun onPause(){
      //need to access videoBGGlobal here
   }
  }
  </code></pre>