Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9228635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:22:22+00:00 2026-06-18T05:22:22+00:00

I’m new to android. I can’t seem to find pertinent forum posts. What has

  • 0

I’m new to android. I can’t seem to find pertinent forum posts.

What has me stumped is that allocateDirect() does create the backing byte[] in Android 4.2 emulator.

More specifically, I allocate a ByteBuffer, and call buffer.put(byte[]) 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.

Here’s the resulting buffer contents just after writing when running the Android 2.2 emulator:

enter image description here

Here’s the resulting buffer contents just after writing when running the Android 4.2 emulator:

enter image description here

The difference seems to be in whether bufferRef.block 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 ByteBuffer.allocate(size).

        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;
        }

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?

Environment:

ADT Build: v21.0.0-519525

Android 2.2 emulator config:

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:

[2012-12-20 10:09:34 – SDK Manager] hw.sdCard=no

[2012-12-20 10:09:34 – SDK Manager] hw.device.manufacturer=Google

[2012-12-20 10:09:34 – SDK Manager] hw.mainKeys=no

[2012-12-20 10:09:34 – SDK Manager] hw.lcd.density=320

[2012-12-20 10:09:34 – SDK Manager] hw.accelerometer=yes

[2012-12-20 10:09:34 – SDK Manager] hw.dPad=no

[2012-12-20 10:09:34 – SDK Manager] hw.device.hash=-708107041

[2012-12-20 10:09:34 – SDK Manager] hw.trackBall=no

[2012-12-20 10:09:34 – SDK Manager] hw.device.name=Galaxy Nexus

[2012-12-20 10:09:34 – SDK Manager] hw.camera.back=none

[2012-12-20 10:09:34 – SDK Manager] hw.sensors.proximity=yes

[2012-12-20 10:09:34 – SDK Manager] hw.battery=yes

[2012-12-20 10:09:34 – SDK Manager] disk.dataPartition.size=200M

[2012-12-20 10:09:34 – SDK Manager] hw.audioInput=yes

[2012-12-20 10:09:34 – SDK Manager] hw.sensors.orientation=yes

[2012-12-20 10:09:34 – SDK Manager] hw.camera.front=none

[2012-12-20 10:09:34 – SDK Manager] hw.gps=yes

[2012-12-20 10:09:34 – SDK Manager] skin.dynamic=no

[2012-12-20 10:09:34 – SDK Manager] hw.keyboard=yes

[2012-12-20 10:09:34 – SDK Manager] vm.heapSize=64

[2012-12-20 10:09:34 – SDK Manager] hw.ramSize=512

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:22:23+00:00Added an answer on June 18, 2026 at 5:22 am

    There is no byte buffer for Android 2.2. The buffer is optional. It was implemented in later releases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I have a jquery bug and I've been looking for hours now, I can't
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.