JakeWharton/ActionBarSherlock — Issue #208: Second time an ActionMode is added, the close button is not clickable
Author: SimonVT
Created: 2012-01-29 12:11:30+00:00
State: open

Rather strange bug in ABS4.

First time an ActionMode is shown, the close button works fine.
Second time an ActionMode is shown, the close button does not react to clicks.
Third+ time the ActionMode is shown, the close button works fine.

This behavior is only observed on 3.0+ when using the compat version of the ActionBar.

This is a rather simple example which should show what I'm talking about:

public class MyActivity extends FragmentActivity {

private ActionMode mActiveActionMode;
private ActionMode.Callback mLastCallback;

private boolean mInActionMode;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mInActionMode = !mInActionMode;
updateActionMode();
}
});
}

void updateActionMode() {
if (!mInActionMode && mActiveActionMode != null) {
mActiveActionMode.finish();

} else if (mInActionMode && mActiveActionMode == null) {
if (mLastCallback == null) mLastCallback = new SomeCallback();
startActionMode(mLastCallback);
}
}

class SomeCallback implements ActionMode.Callback {

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mActiveActionMode = mode;
menu.add(0, 1, 0, "Test");
return true;
}

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}

@Override
public void onDestroyActionMode(ActionMode mode) {
mActiveActionMode = null;
mInActionMode = false;
}
}
}