1

I have a class that loads multiple sounds to create a sound effect library. I use soundPool's setOnLoadCompleteListener to listen for each sound being loaded. As each sound is loaded I count the sounds and when they are all loaded I want to communicate this to the main Activity so it can move to the next step.

The question How to use a local broadcast manager describes how to broadcast between activities really well. However, as I am only wanting to broadcast between a class and the activity that contains it, is using a LocalBroadcastManager in this situation overkill?

Community
  • 1
  • 1
Mel
  • 6,214
  • 10
  • 54
  • 71
  • **"between a class and the activity that contains it,"** What do you mean by "the activity that contains it"? Is it an inner class of the `Activity`? – Squonk May 20 '14 at 01:41

3 Answers3

0

You can try Otto or Green Robot

antslava
  • 346
  • 1
  • 9
0

Yes it's overkill. You don't need a broadcast for this. If your activity is implementing OnLoadCompleteListener then you can simply call a method in your activity when all of your sounds are loaded. If you're creating an object that implements OnLoadCompleteListener, then you can create an argument to the listener's constructor for your activity. When all sounds are loaded you have a pointer to your activity and can call a method on it that way.

cgould
  • 134
  • 5
0

Try using a listener . I have not used SoundPool before but a common way of using and implementing a listener is as follows.

public interface ThisIsMyListener {
    public void triggerListener();
}

public class ThisIsMyClass {
    private ThisIsMyListener lis;

    public  ThisIsMyClass(ThisIsMyListener listener) {
        lis = listener;
    }

    private void triggerListener() {
        lis.triggerListener();
    }
}

You activity will have to implement the listener.

public class MyActivity extends Activity implements ThisIsMyListener
sean
  • 717
  • 2
  • 9
  • 23