I just finished adjusting one of my apps to the new v22.1.1 support & appcompat libraries, see here and here for more details. When I did some testing, something was off with the ActionModes I'm using.
When you start a ActionMode using a startSupportActionMode()
call - it does not matter if you use the now deprecated ActionBarActivity base class or the new AppCompatActivity base class - onPrepareActionMode()
is not being called.
In previous versions, including v21.0.3 & v22.0.0, onPrepareActionMode()
was called automatically, when the ActionMode was initially created using startSupportActionMode()
.
I tested it on a 2.2, 4.4.2 and 5.0 device, so it seems not to be version dependent.
Does anyone know, if this is intended behavior, that's been introduced in v22.1.1, or a bug?
I found this issue, but there's not a lot of feedback here...
Edit May 11 2015:
As mentioned in the Android issue tracker 159527, this issue not only affects the v22.1.x of appcompat and the support library, but also the 5.1 Android implementation.
Two possible temporary solutions at the moment, a general one:
@Override
public ActionMode startSupportActionMode(final ActionMode.Callback callback) {
// Fix for bug https://code.google.com/p/android/issues/detail?id=159527
final ActionMode mode = super.startSupportActionMode(callback);
if (mode != null) {
mode.invalidate();
}
return mode;
}
and a 'quick and dirty' one (when you instantiate your ActionMode):
final ActionMode actionMode = startSupportActionMode(new MyActionMode());
if(actionMode != null) {
actionMode.invalidate();
}
If you don't use appcompat (ActionBarActivity
/AppCompatActivity
) you need to replace startSupportActionMode()
with startActionMode()
.
Unfortunately it's still not clear if this is intended new behavior or a bug. According to the API doc it's a bug/regression, but who knows...