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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:27:34+00:00 2026-06-14T10:27:34+00:00

Beginner here. I have a class with a SoundPool object in it. I would

  • 0

Beginner here. I have a class with a SoundPool object in it. I would like to have the class implement Parcelable so that its instance can be passed between activities (so that I only load the sounds once).

But I am facing a problem in writing the SoundPool object into the parcel. May I know if it is possible at all? (Maybe SoundPool does not implement Parcelable?)

public class SoundSamples { // implements Parcelable{

SoundPool sound;
AudioManager am;
int soundId[] = new int[4];
Context ctxt;

public SoundSamples(Context context) {
    ctxt = context;
}

public void makeSound() {
    Context context = ctxt;

    sound = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
    soundId[0] = sound.load(context, R.raw.c4, 0);
    soundId[1] = sound.load(context, R.raw.cs4, 0);
    soundId[2] = sound.load(context, R.raw.d4, 0);
    soundId[3] = sound.load(context, R.raw.ds4, 0);
}

public SoundPool getSound() {
    return sound;
}

public int[] getSoundId() {
    return soundId;
}

/*
private SoundSamples(Parcel in) {

    // STUCK HERE
    sound = in.readParcelable(null);
    soundId = in.readArray(Integer);
}

public static final Parcelable.Creator<SoundSamples> CREATOR
= new Parcelable.Creator<SoundSamples>() {
    public SoundSamples createFromParcel(Parcel in) {
        return new SoundSamples(in);
    }

    public SoundSamples[] newArray(int size) {
        return new SoundSamples[size];
    }
};

public void writeToParcel(Parcel out, int flags) {

        // AND STUCK HERE 
    out.writeIntArray(soundId);
    out.writeParcelable((Parcelable)sound,0);
}
*/
}

Any help is appreciated. Do point out if this is the correct way to do things at all. Thanks.

  • 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-14T10:27:35+00:00Added an answer on June 14, 2026 at 10:27 am

    You definitely do not want to convert a SoundPool to a Parcel and send it between activities. This is totally inefficient.

    Just store the SoundPool object in a public static variable and you can access it from all your activities.

    For more information, see my answer to Intent and Parcelable object Android

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

Sidebar

Related Questions

Python beginner here. I have a text file that is sorted into columns: fields
Rails beginner here.. I have a users resource where I implemented a callback that's
I'm a beginner in Android. Here I have this code: public class GPS extends
I have another beginner's question that hopefully someone can help with. I'm trying to
Beginner programmer here....hope it makes sense :) I have created a console app that
(note that I'm a total beginner in android programming) I have a class that
R Beginner here. I have a list of class references. Each class has a
Python beginner here, I have a list of lists and want to refer to
Bit of a beginner question here: Say I have a block of xml: <root>
Please help this beginner here... I have a SQL Server 2008 R2 running on

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.