4
\$\begingroup\$

I wrote a small Java activity extension of UnityPlayerActivity similar to what is described in the Unity docs. It has a method for displaying a song picking interface using an ACTION_GET_CONTENT intent. I start this activity using startActivityForResult() and it absolutely kills the performance of my Unity game when it is finished, it drops to about .1 FPS afterwords. I've changed removed the onActivityResult function and even tried starting the activity from inside an onKeyDown event in Java to make sure my method of starting the activity from Unity was not the problem. Heres the code in a basic sense:

package com.company.product;

import com.unity3d.player.UnityPlayerActivity;
import com.unity3d.player.UnityPlayer;
import android.os.Bundle;
import android.util.Log;
import android.content.Intent;

public class SongPickerActivity extends UnityPlayerActivity {

    private Intent myIntent;
    final static int PICK_SONG = 1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i("SongPickerActivity", "OnCreate");
        myIntent = new Intent(Intent.ACTION_GET_CONTENT);
        myIntent.setType("audio/*");
    }

    public void Pick() {
        Log.i("SongPickerActivity", "Pick");
        startActivityForResult(myIntent, PICK_SONG);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

This is causing me a bit more of a headache than it should and I would be thankful for any sort of advice. Does anyone have any experience with using custom activities in Unity Android or any insight on why this is happening or how to resolve this?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

I don't think an Activity is what you are looking for.

Activities are meant to be shown to the user, one at a time. If you're looking to play music in the background of your app you probably want to create a class that handles audio files.

Here's a few android classes that are useful in managing playback of sound.

android.content.res.AssetManager
android.media.AudioManager
android.media.SoundPool
\$\endgroup\$
1
  • \$\begingroup\$ I was going to add the links to the documentation but I'm not allowed to have that many links >.> \$\endgroup\$
    – Tyler
    Nov 12, 2012 at 22:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .