title: ByteBuffer.allocateDirect(size) is not creating backing byte[] in Android 2.2 emulator
body: <p>I'm new to android.  I can't seem to find pertinent forum posts.  </p>
  
  <p>What has me stumped is that <code>allocateDirect()</code> <strong>does</strong> create the backing byte[] in Android <strong>4.2</strong> emulator.  </p>
  
  <p>More specifically, I allocate a ByteBuffer, and call <code>buffer.put(byte[])</code> several times to write the contents of the ByteBuffer.  I then want to hand off the backing byte[] for compression.  It's accessing the backing byte[] that throws the UnsupportedOperationException.</p>
  
  <p>Here's the resulting buffer contents just after writing when running the Android 2.2 emulator:</p>
  
  <p><img src="https://i.stack.imgur.com/j3j9g.png" alt="enter image description here"></p>
  
  <p>Here's the resulting buffer contents just after writing when running the Android 4.2 emulator:</p>
  
  <p><img src="https://i.stack.imgur.com/S1M7E.png" alt="enter image description here"></p>
  
  <p>The difference seems to be in whether <code>bufferRef.block</code> is created (it's created when the ByteBuffer is allocated in the Android 4.2 emulator).  I would prefer to always use a direct ByteBuffer.  As a workaround, I check to see whether I have access to the backing byte[], and if not, re-allocate using <code>ByteBuffer.allocate(size)</code>.</p>
  
  <pre><code>        ByteBuffer buf;
          try {
              buf = ByteBuffer.allocateDirect(this.maxBufferSize);
              if(!buf.hasArray()) { //some API levels either don't expose or create the backing byte[]  
                  buf = null;
                  buf = ByteBuffer.allocate(this.maxBufferSize);
              }
          } catch (Exception e) {
              return false;
          }
  </code></pre>
  
  <p>So, my question is, is there a way to guarantee a direct byte buffer will always have a backing byte[] (assuming enough memory)?  Or do I have to live with this workaround?  </p>
  
  <p>Environment:</p>
  
  <p>ADT Build: v21.0.0-519525</p>
  
  <p>Android 2.2 emulator config:</p>
  
  <p>Updated AVD 'AVD_for_Galaxy_Nexus_by_Google' based on Android 2.2, ARM (armeabi) processor,
  [2012-12-20 10:09:34 - SDK Manager] with the following hardware config:</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.sdCard=no</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.device.manufacturer=Google</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.mainKeys=no</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.lcd.density=320</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.accelerometer=yes</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.dPad=no</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.device.hash=-708107041</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.trackBall=no</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.device.name=Galaxy Nexus</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.camera.back=none</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.sensors.proximity=yes</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.battery=yes</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] disk.dataPartition.size=200M</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.audioInput=yes</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.sensors.orientation=yes</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.camera.front=none</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.gps=yes</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] skin.dynamic=no</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.keyboard=yes</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] vm.heapSize=64</p>
  
  <p>[2012-12-20 10:09:34 - SDK Manager] hw.ramSize=512</p>