onPause(), onResume() Location

Tutorials that use the MapActivity. Many using GPS functionality.

onPause(), onResume() Location

Postby CyberGriZzly » Wed Apr 27, 2011 5:23 pm

0 down vote favorite


Hello guys,

I have a button, when I press it it calls the method whatIsEnabled() (GPS, Network, or both) and registers a location listener. My problem is when I run it with out the onPause() and on Resume methods is work (working in progress so I an gratefull when it work) but when I put the onPause mothos to unregister the listener it creashes. The code:

Code: Select all
private OnClickListener location_button = new OnClickListener() {
      
      @Override
      public void onClick(View v) {
         // TODO Auto-generated method stub
         registerLocListener();
          
        }
   }
   
   private void createLocListener() {
      //locationListener = new Coordonates(drawable, mapView, Map.this);
      
      locationListener = new LocationListener() {
         
         @Override
         public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub
            
         }
         
         @Override
         public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub
            
         }
         
         @Override
         public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub
            
         }
         
         @Override
         public void onLocationChanged(Location location) {
            // TODO Auto-generated method stub
            Toast.makeText(context, "Lat: " + location.getLatitude() + " Lng: " + location.getLongitude() ,Toast.LENGTH_LONG).show();
         }
      };
   }
   
   protected void onResume() {
      registerLocListener();
      super.onResume();
   }
   
   @Override
   protected void onPause() {
      // TODO Auto-generated method stub
      locationManager.removeUpdates(locationListener);
      super.onPause();
   }

   @Override
   protected boolean isRouteDisplayed() {
      // TODO Auto-generated method stub
      return false;
   }
CyberGriZzly
Freshman
Freshman
 
Posts: 2
Joined: Thu Mar 31, 2011 11:13 pm

Top

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests