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 9134807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:43:38+00:00 2026-06-17T08:43:38+00:00

Long story short, I want to test my clone implementation of the android.os.Bundle class

  • 0

Long story short, I want to test my clone implementation of the android.os.Bundle class
against that class to see which is better. I already know my version is likely going to be worse but I want to know how much worse. Are there any benchmarking tools out there for Android that I can use to see which object is bigger in memory and/or takes more processing time to store/retrieve values?

TL;DR:

I looked at the source code for the android.os.Bundle class, and I don’t like how it stores and returns objects. It just stores them in a HashMap<String, Object> and then casts to the requested object’s class (like getString() or getInt()) using a ClassLoader. I feel that this, or any class casting for that matter, violates type-safety and introduces ambiguity at the programming level, which is what static typing aims to prevent, is it not?

I want to create a similar data container class that doesn’t violate type-safety and doesn’t introduce ambiguity. The logically simple yet obviously inefficient way would be to have a Map for each class I want to store.

What I decided on was a single HashMap<String, Integer> that contains key-index mappings for an assortment of Lists for each class I want to store. For example a call to getString(String key) will get the integer index associated with that key from the map if it exists and then try to get the object at that index in the associated ArrayList<String>.

The only ambiguity here would be returning either null (where the index doesn’t exist in the List for that class) or the wrong object of the right class (where the mapped index exists but the original object stored with that key is in another List), which is really the programmer’s responsibility to check for.

Objects of this class are only temporary containers, used to ship data from one place to another in a standardized fashion. They’re not meant to stick around. They’re also not used in the same manner as Bundles, although part of the reason I want a unified data container like this is to be able to easily convert to a Bundle, JSONObject, ContentValues or Cursor and back.

Or maybe the real question is: is casting really all that bad, or am I just going to extreme efforts to avoid it? I guess good programming is really the only way to avoid ambiguity in either case.

Update:

It looks like Bundle only uses the Classloader when it’s unpacking itself from a Parcel, but it makes a call to unparcel() with every put() call. When retrieving it simply casts to the type that the method returns, inside a try-catch block for ClassCastException. That’s probably the simplest way to do it.

  • 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-17T08:43:39+00:00Added an answer on June 17, 2026 at 8:43 am

    Are there any benchmarking tools out there for Android that I can use
    to see which object is bigger in memory and/or takes more processing
    time to store/retrieve values?

    Yes, Android comes with a lot of great tools for developers, it’s recommended to get to know them. Here you have official documentation link for a good start.

    Switch to DDMS perspective, assuming you are in Eclipse.

    Now, these views should be helpful to you in measuring memory:

    • Allocation tracker. You can see which objects take how much memory. During a run you have to press buttons “Start tracking” and later “Get Allocations”.
    • Heap. You can see what amount of memory is taken from the heap.

    To profile your application, see bottlenecks etc. use Traceview. To call it conveniently from Eclipse open Threads view and while running your program click the button with red circle, like “record button”.

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

Sidebar

Related Questions

Long story short, I have a SQL file that I want to import as
Long story short, I have a form for which I want the id field
Long story short, I want to call format with arbitrarily named arguments, which will
Long story short, we found files promoting prescription drugs on our server that we
Long story short, I'm developing a theme template for a blog that enables you
Long story short, the database I'm using needs to get looked at. Until that
Long story short, I'm making a custom Swing component that's basically a JTable with
I am setting up a template system, Long story short: I need/want to check
Long story short, I have an array of integers that represents the .text section
So long story short I have an object model in which several different entity

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.