Search code examples
javaandroidgoogle-mapsmapactivity

Can't finish a MapActivity


I've created this activity for an android application:

http://developer.android.com/resources/tutorials/views/hello-mapview.html

Now I want to finish the MapActivity OnTouch, but I don't know how to do it.

I've tried this, on the HelloItemizedOverlay class but don't work: (I'm using the mapView to get the coordinates of a GeoPoint!)

public boolean onTouchEvent(MotionEvent event, MapView mapView) {
      finish();
}

Many thanks!


Solution

  • Pass the Activity to the HelloItemizedOverlay and call finish() on the activity.

    private Activity mActivity;
    
     public HelloItemizedOverlay(Drawable defaultMarker, Activity activity) {
      super(boundCenterBottom(defaultMarker));
      mActivity = activity;
     }
    
     public boolean onTouchEvent(MotionEvent event, MapView mapView) {
          mActivity.finish(); 
     }