Close Unity Inside Android App - unity3d

Actually I have an Android App in which I run my Unity3D game. Everything works well together. Now, when I launch Unity inside my app the game starts normally but if I try to go back to my AndroidApp intent I received a "SIGNAL 11 SIGSEGV" and Unity just close.
This happens when I'm drawing a Menu inside Unity and press "Exit" button to close Unity but if I do the same with the Android back buton Unity closes normally without problems.
I'm using plugins in Unity to achieve this behaviour.
My Function in Unity Side :
public void ExitGame()
{
#if UNITY_ANDROID
AndroidJavaClass unityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject> ("currentActivity");
activity.Call ("ReturnToMainActivity", "Hello");
#endif
}
Function in Android Side :
public void ReturnToMainActivity (String someText)
{
Log.v("Unity", "Finish Unity from Android" );
this.mUnityPlayer.quit();
UnityPlayer.currentActivity.finish();
}
Again, this works normally if I press the Android Back Button inside Unity app but when I try to do the same with an Unity GUI.Button I received a "SIGNAL 11 SIGSEGV". In Both Cases logcat print the message "Finish Unity from Android" so I think Unity calls the function normally but in some Point just crashes.
Someone post faced the same problem but I can't figure out how he solve it.
SIGNAL 11 SIGSEGV crash Android

Ok, I just figure out how to do this.
In my function inside Android Side:
public void ReturnToMainActivity (String someText)
{
UnityPlayer.currentActivity.runOnUiThread(new Runnable(){
public void run()
{
Log.v("Unity", "Aplicacion de Unity terminada desde Android" );
ElJuegoActivity.this.mUnityPlayer.quit();
UnityPlayer.currentActivity.finish();
}
});
}
And that does the trick. No issues or problems.
NOTE: This is the "answer" the OP originally included at the end of his question. I've separated it into its own CW answer. If the OP returns and wants to post it himself, by all means ping me

Related

Disable Unity Debug Canvas

For about an hour ago a Debug Canvas started Instantiating on Play.
I've searched around on the internet but can't seem to find anything.
Are there by any chance some of you who might know how to disable it as it's taking up about half of the screen?
Edit:
I tried to install the project on another computer and it doesn't show up. So idk if it has anything to do with the project or Unity itself.
Image
Add this code to one of your scripts on Awake or Start:
UnityEngine.Rendering.DebugManager.instance.enableRuntimeUI = false;
This is mentioned in documentation
You have to be on CoreRP 12 or later as mentioned here
Try Left Ctrl + Backspace to toogle it, or remove the Universal RP (Render Pipeline) package or disable it by code:
bool debugupdater_disabled = false;
private void Update()
{
if (debugupdater_disabled)
return;
GameObject debugUpdater = GameObject.Find("[Debug Updater]");
if(debugUpdater != null)
{
Destroy(debugUpdater);
debugupdater_disabled = true;
Debug.Log("done");
}
}

Why the IRtcEngine instance is not created?

i'm trying to implement a voice chat in my Unity game using agora.io. I followed the official start up tutorials and I put the code below in a script attached to an empty Gameobject in the scene:
My simple start up script
So, at the Start, the IRtcEngine instance should be created as I call the IRtcEngine.GetEngine(agoraAppID) method. The problem is that, instead od returnig the instance, this method prints an error log: "Create engine failed, error code: -7"
I looked up what the error code 7 means: "A method is called before the initialization of RtcEngine. Ensure that the RtcEngineinstance is created and initialized before calling the method".
So I tried commenting everything but the line in which the IRtcEngine.GetEngine(agoraAppID) method is called, but the error still pops up. It pops up even when I play the agora demo scene "HelloUnity".
I also tried removing the agora package and importing it again. It worked because after that the instance was created correctly, but after a few times, the error started popping up again.
Unity version: 2020.3.3f1
Agora version: 3.3.1.71
What could the problem be? Is it a bug?
I had the same issue with the same error code. Closing all Unity instances and rebooting my computer was helped me.
Usually, it happens if you don't leave the channel properly. So, putting
rtcEngine?.LeaveChannel()
to
OnDestroy()
may be a good solution.
should look something like this. don't forget the variable declaration up top.
public class Launch : MonoBehaviour
{
public IRtcEngine mRtcEngine;
void Start()
{
string agoraAccountId = "4ca78bc86f23hhhhhhhhh4444444444";
if (mRtcEngine != null)
{
Debug.Log("Agora engine exists already!!");
return;
}
mRtcEngine = IRtcEngine.GetEngine(agoraAccountId);
I suggest you join the Agora slack channel (it is easy to join) where you can get answers quickly.
Please take a look at the Demo project code and watch out how the sample app handles the life cycle in Unity. In your simple script, there is no clean up code on destroy. You left certain socket/ports open on the system. That's why when you get some success on a fresh install but not the subsequent run.

Virtual Keyboard not opening in Unity3D with Steam/MRTK

I'm developing with Unity using the MRTK (if that matters) and my project setup is using "PC,Mac &Linux Stand Alone", my player settings are set to enable VR.
I'm copying and pasting directly the code from Unity to open the keyboard, and that function is the first one I call when opening the scene, and yet I can't see it. Is there anything wrong/buggy with it?
I even tried it on a completely empty project. Nothing happens.
Directly from Microsoft:
public TouchScreenKeyboard keyboard;
private void Start()
{
OpenSystemKeyboard();
}
public void OpenSystemKeyboard()
{
keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, false, false);
}
No error message, no console message, just nothing....
The API in question I believe is only documented to work for the following platforms:
iOS
Android
Windows Store Apps (AKA UWP apps AKA Universal Windows Platform apps)
Since the build process is uses PC/Mac/Linux, it's not a WSA/UWP app, so I wouldn't expect that to show up given Unity's documentation here:
https://docs.unity3d.com/ScriptReference/TouchScreenKeyboard.html
The older version of the MRTK (HTK) had a keyboard prefab that could be used, though note that that branch is fairly old at this point:
https://github.com/microsoft/MixedRealityToolkit-Unity/blob/htk_release/Assets/HoloToolkit/UX/Prefabs/Keyboard.prefab

pause and resume listeners not working in phonegap on iOS4.3 and iOS 5

I was making a native app in iPhone4 with iOS 4.3
in my Body onLoad i m adding
document.addEventListener("pause", Game.prototype.pauseListener.bind(this), false);
document.addEventListener("resume", Game.prototype.resumeListener.bind(this), false);
and in that same file i m writing a function
Game.prototype.resumeListener= function()
{
console.log("in resumeListener");
this.PauseGame(false);
}
Game.prototype.pauseListener= function()
{
this.PauseGame(true);
}
this code is working perfectly fine in Android and when i manually minimise the app, but when the application is interrupted by a voice incoming call the application dont pause.
Basically Pause and Resume event are not fired.
I m using Phonegap1.4.1
I believe your event listeners are not being established because you are using Object.bind() on the handler functions, and .bind() is not available in the iOS WebKit widget. (This is surpising because .bind() is available in the desktop WebKit (Chrome and Safari) versions.)
The easy solution is to add a polyfill definition for Object.bind(). I use the one from the MDN bind documentation page, and haven't had any problems with it.
sorry but i cant make a comment yet ;)
have you checked the two other events (active and resign only for ios)? more information: http://shazronatadobe.wordpress.com/2012/03/14/apache-cordova-lifecycle-events-in-ios-4-versus-ios-5/
or see iOS Quirks in the documentation: http://docs.phonegap.com/en/1.6.1/cordova_events_events.md.html#pause
You need to add your listeners in the deviceready instead of in the onLoad.
Just like here for example
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
document.addEventListener("pause", onPause, false);
}
function onPause() {
}
Hope it helps :)

PhoneGap Events Not Firing On iPhone

I've started developing for iPhone using PhoneGap and an iPhone running iOS 5. With the following code, the deviceready and online events appear to fire when the application starts but none of the others, in particular, the resume / pause events appear to. I've tried using the menu button to close the app and then re-open it but nothing appears to fire the resume event.
If anyone could shed any light on this it would be much appreciated.
Thanks in advance!
window.addEventListener('load', function () {
document.addEventListener('deviceready', onDeviceReady, false);
}, false);
function onDeviceReady() {
document.addEventListener('resume', onResume, false);
document.addEventListener('pause', onPause, false);
document.addEventListener('online', onOnline, false);
document.addEventListener('offline', onOffline, false);
}
function onResume() {
alert('resume');
}
function onPause() {
alert('pause');
}
function onOnline() {
alert('online');
}
function onOffline() {
alert('offline');
}
For me this was an ID10-T error: my PhoneGap app was redirecting to a URL which I had changed in one place but not in the other. The result was it looked like I was running my development code but I was actually running against a remote server running code without onResume and onPause events!
BTW, documentation for these events can be found at http://docs.phonegap.com/en/1.4.1/phonegap_events_events.md.html