title: Android Kotlin Testing for Intent putExtra Value
body: <p><code>android studio 4.1.1</code> and Kotlin.  I'm a beginner learning via tutorials.</p>
  <p>I have an activity in which I am using an Intent to go to another activity.  I'm using <code>intent.putExtra</code>:</p>
  <pre><code>val intent = Intent(this, WeightExercise::class.java)
  intent.putExtra(&quot;POSITION&quot;, positionToString)
  startActivity(intent)
  </code></pre>
  <p>In the WeightExercise activity I get the value passed with:</p>
  <pre><code>// with line numbers:
  
  80: var myPosition = intent.getStringExtra(&quot;POSITION&quot;).toString()
  81: var position = myPosition.toInt()
  </code></pre>
  <p>This works.  I get the string value in <code>POSITION</code>.</p>
  <p>Problem: I have another activity that uses an Intent to go to the WeightExercise activity.  It is NOT passing in a value via the intent.  When this happens, line 81 (above) in WeightExercise activity causes an error:</p>
  <pre><code>Caused by: java.lang.NumberFormatException: For input string: &quot;null&quot;
  at java.lang.Integer.parseInt(Integer.java:615)
  at java.lang.Integer.parseInt(Integer.java:650)
  at com.johndcowan.liftit.WeightExercise.onCreate(WeightExercise.kt:81)
  </code></pre>
  <p>I've tried a few <code>if()</code>s to test for a null or empty value, but nothing gets me past this error.</p>
  <pre><code>if ( intent.getStringExtra(&quot;POSITION&quot;).toString().isNullOrEmpty() ) {...}
  if ( myPosition.isNullOrEmpty() ) {...}
  if ( myPosition == null ) {...}
  </code></pre>
  <p>Is there a better way to test for a named string <code>POSITION</code> in an intent?</p>
  <p>thanks for any tips.</p>