I tried to add a back button in my Map activity but it always crashes that is my code for the action bar
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mapsanlocations);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
geocoder = new Geocoder(this, Locale.getDefault());
actionBar = getActionBar();
actionBar.setHomeButtonEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
and I also included its parent in the android mainfest
<activity android:name=".Mapsanlocations" android:parentActivityName=".MainActivity" android:label="@string/title_activity_mapsanlocations"></activity>
Thanks in advance.