cancel
Showing results for 
Search instead for 
Did you mean: 

How to force close an app on Android?

Weitin
Level 4
I'm trying to use an app to launch another app using the following code.
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage",bundleId);
ca.Call("startActivity", launchIntent);
I'll call this app the launcher and the other apps are games.
I can launch games from the launcher correctly, however I noticed the launcher app will still have a running instance (when returning from games and loading through Oculus home menu). The Oculus Quest basically only allows you to run one app at a time, which confuses me. Using the same code, I can load the launcher where I left off with no problems. But once I've launched a game, return to the launcher, then try to launch the same game, it says "AppName has stopped". I think the related error I get is: 'Consumer closed input channel or an error occurred. events=0x9'

I think a solution is to force close an app when I load the new app. How can I properly do this? Application.Quit()?
1 REPLY 1

Weitin
Level 4
So it turns out Application.Quit() is the reason my games are crashing when I load them after the first time. Application.Quit() on Android seems to exit the app, but doesn't fully remove the app which is causing the crashing behaviour. Use this instead:
System.Diagnostics.Process.GetCurrentProcess().Kill();