- Home /
Call a Android Studio method from Unity
Hi,
I implemented a game in Unity and a menu in Android Studio. I already connected them by exporting the Unity game as library and import this into my Android Studio project as a module.
In the game you can get a score and I want to show a highscore list in the menu.
Therefore I tried this in my Unity project:
AndroidJavaClass jc= new AndroidJavaClass("com.company.jana.ghostapp.CallFromUnity");
jc.Call("unityBack", new object[] { score } );
And that's the class in Android Studio to call:
package com.company.jana.ghostapp;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import com.Company.GhostGame.UnityPlayerActivity;
public class CallFromUnity extends UnityPlayerActivity {
public static final String logTag = MainActivity.class.getSimpleName();
public void unityBack(String newScore) {
Log.d(logTag, "call from unity");
Toast.makeText(this, "Score: " + newScore, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
}
Using this I didn't get any errors. Also my log doesn't appear and nothing happens (no toast and no switching activity).
Does anyone has an idea to solve this problem?
Thanks for your help!
Jana
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612180210im_/https://answers.unity.com/themes/thub/images/avi.jpg)