title: onPrepareActionMode not called when creating ActionMode
body: <p>I just finished adjusting one of my apps to the new v22.1.1 support &amp; appcompat libraries, see <a href="https://chris.banes.me/2015/04/22/support-libraries-v22-1-0/">here</a> and <a href="http://android-developers.blogspot.co.uk/2015/04/android-support-library-221.html">here</a> for more details. When I did some testing, something was off with the <a href="https://developer.android.com/reference/android/support/v7/view/ActionMode.html">ActionModes</a> I'm using.</p>
  
  <p>When you start a <a href="https://developer.android.com/reference/android/support/v7/view/ActionMode.html">ActionMode</a> using a <code>startSupportActionMode()</code> call - it does not matter if you use the now deprecated <a href="https://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html">ActionBarActivity</a> base class or the new <a href="https://developer.android.com/reference/android/support/v7/app/AppCompatActivity.html">AppCompatActivity</a> base class - <code>onPrepareActionMode()</code> is not being called. </p>
  
  <p>In previous versions, including v21.0.3 &amp; v22.0.0, <code>onPrepareActionMode()</code> was called automatically, when the ActionMode was initially created using <code>startSupportActionMode()</code>. </p>
  
  <p>I tested it on a 2.2, 4.4.2 and 5.0 device, so it seems not to be version dependent.</p>
  
  <p>Does anyone know, if this is intended behavior, that's been introduced in v22.1.1, or a bug?</p>
  
  <p>I found this <a href="https://code.google.com/p/android/issues/detail?id=159527">issue</a>, but there's not a lot of feedback here...</p>
  
  <p><strong>Edit May 11 2015:</strong></p>
  
  <p>As mentioned in the <a href="https://code.google.com/p/android/issues/detail?id=159527">Android issue tracker 159527</a>, this issue not only affects the v22.1.x of appcompat and the support library, but also the 5.1 Android implementation.</p>
  
  <p>Two possible temporary solutions at the moment, a general one:</p>
  
  <pre><code>@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;
  }
  </code></pre>
  
  <p>and a 'quick and dirty' one (when you instantiate your ActionMode):</p>
  
  <pre><code>final ActionMode actionMode = startSupportActionMode(new MyActionMode());
  if(actionMode != null) {
      actionMode.invalidate();
  }
  </code></pre>
  
  <p>If you don't use appcompat (<code>ActionBarActivity</code>/<code>AppCompatActivity</code>) you need to replace <code>startSupportActionMode()</code> with <code>startActionMode()</code>.</p>
  
  <p>Unfortunately it's still not clear if this is intended new behavior or a bug. According to the <a href="http://developer.android.com/reference/android/view/ActionMode.Callback.html#onPrepareActionMode%28android.view.ActionMode,%20android.view.Menu%29">API doc</a> it's a bug/regression, but who knows...</p>