- Home /
launch android activity from unity
Hi , I have an android app which by pressing a button it should get me to the AR scene built in unity3d and vuforia.
I have made my AR project in unity and exported it to eclipse and then added other activities to it.
when I press the button I do this code :
Intent intent= new Intent(getApplicationContext(), QCARPlayerNativeActivity.class); startActivity(intent);
and the app goes to the AR scene. Now I want to be able to go back to the normal activity which has the button. I tried pressing back but it didn't work I also found this page : http://stackoverflow.com/questions/7754373/integrating-unity-with-eclipse-back-button-click And I tried to use it but again no luck. I think it doesn't work because I go to QCARPlayerNativeActivity class but I don't have any access to this class to override its onBackPressed() function. I'll appreciate if you can help me with this. Thanks very much
Answer by steakpinball · Feb 03, 2015 at 04:15 PM
The code you have for launching the Unity scene is good. The problem is the unity activity doesn't watch for the back button press. Since you can't modify the QCAR activity to finish, you can do it from inside your unity scene.
In your Unity scene you can have a script looking for a back button press. The back button looks like the escape key to Unity. Quitting the Unity activity will return you to the previous activity. Application.Quit()
finishes the activity returning you to the activity which launched it.
void Update() {
if (Input.GetKeyDown(KeyCode.Escape)) {
Application.Quit();
}
}
Thanks $$anonymous$$ but doing so will get you out of the application, I want to launch another activity
This unity code is equivalent to the android code linked in the question.