Starting a Java activity in Unity3d Android

Posted by Matthew Pavlinsky on Game Development See other posts from Game Development or by Matthew Pavlinsky
Published on 2012-03-19T23:08:21Z Indexed on 2012/03/19 23:39 UTC
Read the original article Hit count: 516

Filed under:
|
|
|

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?

© Game Development or respective owner

Related posts about java

Related posts about android