Android : Back button is acting odd
<p>I have a strange problem and really dont know where to start debug. I have 2 activities one that holds a googlemap view and when the user taps the marker on the view i start a new activity that shows a detailed description of that marker. If i hit the back buttton on my detalied activity it returns me to the map activity, so far so good. BUT if i tap a new (or same) marker i get to the detailed activity again (all fine) if i try to hit the back button again i get returned to the detailed activity that i tapped the very first time, and i can hit back once more and finaly get to the map activity again.</p>

<p>if i keep debugggin i can get up to 10 activities that i have to push back on before i finaly get to the map activity again </p>

<p>what the heck is going on ? does android forget history or something due to i implement the map activity instead of activity ? </p>

<p>anyone that has an idea of where to start looking for the problem </p>

<p>Here comes a lot of code:</p>

<p>map activity</p>

<pre><code>public class SpotGuideMapActivity extends MapActivity
{
    protected MapView mapView;
    protected MapController mapController;
    protected List&lt;Overlay&gt; mapOverlays;
    protected Drawable overlayIcon;
    protected SpotGuideOverlay spotsOverlay;
    protected MyLocationOverlay myLocOverlay;

    protected ArrayList&lt;SpotItem&gt; _spots;

    protected Button ButtonHome;
    protected Button ButtonPreferences;

    protected Intent _intent = null;


    private SpotGuideDbAdapter _spotDbAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.spot_map);
        _intent = getIntent();
        ActivityHelper.createInstance(this).setTopBarTitle("Spot kortet");

        ButtonPreferences = (Button)findViewById(R.id.btnPreferences);
        ButtonPreferences.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v) 
            {


                startActivity(new Intent(getApplicationContext(), GlobalPreferencesActivity.class));         
                overridePendingTransition(R.anim.slide_right_in,R.anim.slide_right_out);
            }
        });

        ButtonHome = (Button)findViewById(R.id.btnHome);
        ButtonHome.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v) 
            {
                startActivity(new Intent(getApplicationContext(), HomeActivity.class));         
                 overridePendingTransition(R.anim.slide_left_in,R.anim.slide_left_out);
            }
        });


        //mapView.invalidate();
    }

    @Override
    protected void onResume() 
    {
        super.onResume();
        if(_intent.hasExtra("latitude") &amp;&amp; _intent.hasExtra("longitude"))
        {
            String latitude = _intent.getStringExtra("latitude");
            String longitude = _intent.getStringExtra("longitude");
            double lat = Double.parseDouble(latitude);
            double lon = Double.parseDouble(longitude);

            GeoPoint point = new GeoPoint((int)(lat * 1E6) , (int)(lon * 1E6));
            initMapView(point);
        }
        else
        {
            initMapView(null);
        }

        drawSpotMarkers();

    }
    @Override
    protected void onPause() 
    {
        super.onPause();
        myLocOverlay.disableCompass();
        myLocOverlay.disableMyLocation();

    }

    protected void initMapView(GeoPoint centerPoint) 
    {

        mapView = (MapView)findViewById(R.id.spotGuideMap);
        mapView.setBuiltInZoomControls(true);
        mapController = mapView.getController();

        //current location overlayer
        myLocOverlay = new MyLocationOverlay(this, mapView);
        myLocOverlay.enableCompass();
        myLocOverlay.enableMyLocation();

        mapView.getOverlays().add(myLocOverlay);

        GeoPoint point = null;
        if(centerPoint == null)
        {
            point = myLocOverlay.getMyLocation();
            if(point == null)   
            {
                point = new GeoPoint((int)(55.5616508394963 * 1E6) , (int)(12.563638687133789 * 1E6));
            }
        }
        else 
        {
            point = centerPoint;
        }
        //get the last know location, be fresh so use last fix
        //Location location = myLocOverlay.getLastFix();
        //GeoPoint locationPoint;

        //locationPoint = new GeoPoint((int)(location.getLatitude() * 1E6) , (int)(location.getLongitude() * 1E6));

        mapController.animateTo(point);
        mapController.setZoom(10);      
    }

    protected void drawSpotMarkers() 
    {
        mapOverlays = mapView.getOverlays();

        overlayIcon = getResources().getDrawable(R.drawable.map_icon_pink);
        spotsOverlay = new SpotGuideOverlay(overlayIcon, this);

        _spotDbAdapter = new SpotGuideDbAdapter(this).Open();
        _spots = _spotDbAdapter.getAllSpots();

        for (SpotItem spot : _spots) 
        {
            double lat = Double.parseDouble(spot.getLatitude());
            double lon = Double.parseDouble(spot.getLongitude());

            GeoPoint point = new GeoPoint((int)(lat * 1E6) , (int)(lon * 1E6));

            OverlayItem overlayitem = new OverlayItem(point, spot.getSpotTitle(), Integer.toString(spot.getId()));

            spotsOverlay.addOverlay(overlayitem);
        }


        mapOverlays.add(spotsOverlay);


    }


    @Override
    protected boolean isRouteDisplayed() 
    {
        return false;
    }

}
</code></pre>

<p>detailed activity</p>

<pre><code>public class SpotGuideDescriptionActivity extends BaseActivity
{
    private SpotGuideDbAdapter _spotDbAdapter;

    protected Button ButtonHome;
    protected Button ButtonPreferences;

    protected Button ButtonBacktoMap;

    protected TextView tvSpotTitle;
    protected TextView tvSpotType;
    protected TextView tvWindDirection;
    protected TextView tvContent;

    protected Intent _intent = null;
    protected SpotItem item;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.spot_description);
        _intent = getIntent();

        this.getActivityHelper().setTopBarTitle("Spot beskrivelse");

        tvSpotTitle = (TextView)findViewById(R.id.spotDescTitle);
        tvSpotType = (TextView)findViewById(R.id.spotDescType);
        tvWindDirection = (TextView)findViewById(R.id.spotDescWind);
        tvContent = (TextView)findViewById(R.id.spotDescContent);

        ButtonBacktoMap = (Button)findViewById(R.id.btnBackToMap);
        ButtonBacktoMap.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v) 
            {
                Intent intent = new Intent(getApplicationContext(), SpotGuideMapActivity.class);
                intent.putExtra("latitude", item.getLatitude());
                intent.putExtra("longitude", item.getLongitude());
                startActivity(intent);                    
                overridePendingTransition(R.anim.slide_left_in,R.anim.slide_left_out);
            }
        });

        ButtonPreferences = (Button)findViewById(R.id.btnPreferences);
        ButtonPreferences.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v) 
            {


                startActivity(new Intent(getApplicationContext(), GlobalPreferencesActivity.class));         
                overridePendingTransition(R.anim.slide_right_in,R.anim.slide_right_out);
            }
        });

        ButtonHome = (Button)findViewById(R.id.btnHome);
        ButtonHome.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v) 
            {
                startActivity(new Intent(getApplicationContext(), HomeActivity.class));         
                 overridePendingTransition(R.anim.slide_left_in,R.anim.slide_left_out);
            }
        });

        init();
    }

    private void init()
    {
        if(_intent.hasExtra("spot_id"))
        {
            int id = _intent.getIntExtra("spot_id", 0);
            _spotDbAdapter = new SpotGuideDbAdapter(this).Open();

            item = _spotDbAdapter.getSpot(id);
            tvSpotTitle.setText(item.getSpotTitle());
            tvSpotType.setText(item.getSpotType());
            tvWindDirection.setText(item.getWindDirections());
            tvContent.setText(item.getSpotDescription());
        }
    }
}
</code></pre>

<p>And i init the tap in my OverlayItem like this</p>

<pre><code>public boolean onTap(int index)
    {
        OverlayItem item = mOverlays.get(index);

        Intent descIntent = new Intent(currentContext.getApplicationContext(), SpotGuideDescriptionActivity.class);
        descIntent.putExtra("spot_id", item.getSnippet());
        currentContext.startActivity(descIntent);

        return false;

    }
</code></pre>

<p>it is not the BackToMap button that i use, it is the back button on all phones </p>
