I have a performance issue when using MapFragment
together with the action bar menu.
The bug emerges when three conditions are met
The fragment transaction is performed before the options menu is closed, this causes the weird behavior.
Instead of directly performing the fragment transaction, post it on the Handler
. Once the options menu is closed, then the fragment transaction will be performed.
Try this :
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final Fragment fragment;
if (item.getTitle().equals(MAP)) {
fragment = mMapFragment;
} else {
fragment = new Fragment();
}
Handler handler = new Handler();
handler.post(new Runnable() {
@Override
public void run() {
getFragmentManager()
.beginTransaction()
.replace(R.id.main, fragment)
.addToBackStack(null)
.commit();
}
});
return true;
}