I read through the forum that you gave me.
However, I could only find out the way to handle the H/W keys.
I am searching a way to close an Activity by a program but not an Application.
I’m starting an Activity that made with Unity from another Android Activity.
So, I just want to close the unity activity not the entire application.
Application.Quit(); will close whole application.
shinobu_siv, did you figure out a way to do this? I’m having the exact same problem. If they click back I want it to return to the activity that called it.
Thanks Fenyx4, that is getting me closer. However, the whole activity stack is still closing. I actually see my calling activity flash on the screen briefly before it too is finished. I threw in a toast message on my onResume method in the calling activity and it does show briefly, so the unity activity is returning to the calling activity, but it then destroys that too. Any ideas why calling finish on the UnityPlayer would kill the whole activity stack?
yaa its possible.inside keycode.backkey write System.exit(0).It wil close the activity.If facing some problem let me know what codes you write on keycode.back?
I am having the same problem, I need to launch a Unity Activty from within my larger android app, end the unity activty when they hit a button, thus returning to the root activity. Everything runs fine, but It seems like somewhere in the Unity player destroy function it is forcing the entire app to close and not just the unity player activity.
I’m using java in eclipse, i guess it’s te same code cause it’s the android/java compiler that compiles it.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK) //when the back button is pressed
{
finish(); //Close activity
return true; //onKeyDown is handled by user
}
return super.onKeyDown(keyCode, event);
}
I didnt fix it , the only option was to leave the Unity player activity stopped in the background, and resumes when needed. This puts extra memory constraints on the program and is something that Unity needs to adress.
I think most of you people (and most users and many other Android developers) have no idea how Android works.
It’s absolutely ok to minimize/put the current app in background. It won’t slow down the system at all. Apps that are in background typically don’t consume CPU. They are in sleep state. And yes, while they are still loaded in memory, this doesn’t slow the Android device at all.
If there is memory left, newly started apps and activities will use that free memory. If the device runs low on memory, the Android OS will release the apps in background to free the memory.
What you have to do is, to save any vital data when the app gets in background, because you don’t know if or when the app may be killed from the memory by the OS. So basically in “onPause” you must save your app informations and call it in “onRestart” (if the app was killed) or in onResume if it wasn’t.
That’s when you write traditional Android Apps in Java. Unity has similar ones: OnApplicationPause and OnApplicationFocus, which should be used to save the current game’s progress. Haven’t tested it yet, but it should work on Android too.
I’m also experiencing issues with this. We use Application.Quit() from withing the game, and I’ve also tried Unityplayer.currentActivity.finish().
The activity closes and I’m returned to the previous activity, but the problem comes in when attempting to reload the game activity. The newly created gaem activity crashes as it starts loading.
I did some further investigation and used DDMS to profile - revealing that there’s a GLThread that stays left behind after each game activity end, regardless of which way I end the activity.
Anyone have any insight regarding this…please…I’m at wit’s end here