The game can not exit completely

I use these lines of code to exit the game by pressing Back button in Android:

public override void Update(GameTime gameTime) { base.Update(gameTime); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { ExitGame(); androidActivity.Finish(); } }

I got to Home Screen but game would be failed to start after that at license screen (i'm using trial version of Xamarin Studio). It was like license screen then back to Home Screen. Then it can be successfully launched again.

Is is because I missed something or it's the limitation of trial version?

Posts

  • Hmmm, my understanding (which may be wrong!) is that on mobile platforms such as Android and iOS that an app should NOT try and terminate itself.

    The host operating system will do this automatically when it needs memory for an active app or to launch a new app and will kill background apps off in order to fulfil any memory requests.

    Users can also force an app to terminate using the host operating system to do so using the mechanism provided by it.

  • FedorBushlanovFedorBushlanov VNMember ✭✭

    Actually in apps which use CocosSharp back button simply does not work and has no effect, so above mentioned method is good to capture back button pressed event. But the question is how to send apps to foreground then or exit is still there...

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai
  • FedorBushlanovFedorBushlanov VNMember ✭✭
    edited January 2015

    No, unfortunately. The goal is simple - to let user press "home" button and restore the app whenever he wants from the "recent" list. Same to "back" button, but it is later story. But it does not work, even with default BouncingGame example from CocosSharp. All I have after press on app in "recent" list is:

    System.Diagnostics.Debugger.Mono_UnhandledException (ex={System.NullReferenceException: Object reference not set to an instance of an object
    at Microsoft.Xna.Framework.Graphics.EffectPass.Apply ()
    ...
    at CocosSharp.CCApplication.Draw (Microsoft.Xna.Framework.GameTime)
    ...

    If to debug, I see that for some yet unknown reasons "ApplicationWillEnterForeground" function is called twice after getting the app from "recent", and the second time it is called as function of newly created class object, because I can see that all class members are not initialized. Also, AndroidGameActivity.OnCreate is called, so we re-create everything in it while it is supposed to just get back the app from background state. At this point I don't really understand how to manage this with all CocosSharp and seems there is no much help in Internet. So any help is much appreciated!

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Do have AlwaysRetainTaskState = true, when defining your activity?

  • Han.HoangHan.Hoang USMember

    @kjpou1‌ Yes, we do.
    As @FedorBushlanov‌ mentioned, after we started app from paused we got 'ApplicationWillEnterForeground' in CCApplicationDelegate called twice somehow.
    First time, we have the our GameScene, but on the second called, GameScene is null then jump to onDestroy(). I don't know when/where GameScene was assigned value or reset. Is it implicitly called somewhere?

Sign In or Register to comment.