title: Getter for defaultDisplay: Display!' is deprecated. Deprecated in Java
body: <p>I need the width of the screen. But recently found Android <code>defaultDisplay</code> deprecacted with message:</p>
  <p><em>Getter for defaultDisplay: Display!' is deprecated. Deprecated in Java</em></p>
  <p><strong>Code:</strong></p>
  <pre><code>val displayMetrics = DisplayMetrics()
  windowManager.defaultDisplay.getMetrics(displayMetrics)
  return displayMetrics.widthPixels
  
  </code></pre>
  <p>Please suggest an alternative.</p>