title: how to handle a getIntent() method with java nullpointerexception
body: <p>I have 2 activities in my application, <strong>Activity1</strong> and <strong>Activity2</strong>.When the app launches Acitivity1 is the the one that is called.Clicking on a button in Activity1 should take you to Activity2.</p>
  
  <p>In Acivity2,some data processing is done then i send back data to Activity1 using an intent like this:</p>
  
  <pre><code>Intent in=new Intent(getApplicationContext(), Activity1.class);
    in.putExtra("data", data);
      startActivity(in);
  </code></pre>
  
  <p>Then getting back to Activity1 i obtain the intent data:</p>
  
  <pre><code> protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity1);
  
      String data =(getIntent().getExtras().getString("data"));
  </code></pre>
  
  <p>The problem here is that the first time the app launches it checks for the intent data and it does not exist so i get the nullpointerexception error.how can i make sure it checks for the intent data when Activity2 is the previous class?</p>