Code example for SparseIntArray

Methods: get, indexOfKey

0
     * 
     * @param resId Resource ID of the sound to be loaded. 
     * @return The sound pool identifier for the resource. 
     */ 
    public int preloadSound(int resId) {
        if (mResourceIdToSoundMap.indexOfKey(resId) >= 0) {
            return mResourceIdToSoundMap.get(resId);
        } 
 
        final int soundPoolId;
        final String resType = mResources.getResourceTypeName(resId);
 
        if ("raw".equals(resType)) {
            soundPoolId = mSoundPool.load(mContext, resId, 1);
        } else if ("array".equals(resType)) {
            final int[] notes = mResources.getIntArray(resId);
            soundPoolId = loadMidiSoundFromArray(notes, false);
        } else { 
            LogUtils.log(this, Log.ERROR, "Failed to load sound: Unknown resource type");
            return -1; 
        }