title: onStop(), onPause(), onCreate(), onResume(), and GPS
body: <p>I have an app working that is <code>GPS</code> based.  It has many activities and all use the <code>GPS</code>.  For example, one activity shows the distance to a location, another shows the speed and direction.  I set up and call <code>requestLocationUpdates()</code> in <code>onCreate()</code> and call <code>removeUpdates()</code> in <code>onPause()</code>.</p>
  
  <p>This all works but the <code>GPS</code> blinks and has to re-acquire when switching activities.  I did a test and if I put the <code>removeUpdates()</code> in <code>onStop()</code> instead of in <code>onPause()</code> there is no blinking.  Apparently <code>onStop()</code> is called after the new activity starts which explains the lack of blinking.</p>
  
  <p>I have read the posts on this subject and there seems to be a difference of opinion.  However, it looks like I should use <code>onStop()</code> and am wondering if there is any reason I should not.  </p>
  
  <p>The second issue is that there is no <code>onResume()</code> code so there is no <code>GPS</code> after a back-arrow or after turning the screen off and on.  I should fix this.  Right now my <code>onCreate()</code> code creates the location manager and basically has all my code in it.  It looks like following the life cycle flow chart that I should move the <code>removeUpdates()</code> to onStop and move the creation of the lm and ll to <code>onStart()</code>.  Is this correct?</p>
  
  <p>Here is my <code>onCreate()</code> code:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.set);
      textView1 = (TextView)findViewById(R.id.textView1);
      lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
      ll = new mylocationlistener();
      lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
  }
  </code></pre>
  
  <p>Here is my onPause code:</p>
  
  <pre><code>    @Override
      protected void onPause() {
          super.onPause();
          if(lm != null) {
              lm.removeUpdates(ll);
          }
          ll = null;
          lm = null;
      }
  </code></pre>
  
  <p>So I think I should just change the onPause() to onStop() and make onStart() this:</p>
  
  <pre><code>@Override
  public void onStart() {
      super.onStart();
      lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
      ll = new mylocationlistener();
      lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
  }
  </code></pre>
  
  <p>And my onCreate code as this;</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.set);
      textView1 = (TextView)findViewById(R.id.textView1);
    }
  </code></pre>
  
  <p>This said, I am kind of new to all this and this is my first application so I would like to know what I am missing here.</p>