Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Move task to back in Windows Phone

Discussion in 'Scripting' started by NatsXD, Feb 17, 2017.

  1. NatsXD

    NatsXD

    Joined:
    Feb 17, 2017
    Posts:
    5
    To move the application to background in Android, we can do:
    Code (CSharp):
    1. AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
    2. activity.Call<bool>("moveTaskToBack", true);
    Anyone knows how to do the same in Windows Phone?
     
    Last edited: Feb 17, 2017
  2. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    What exactly do you want to do? Windows 10 (Mobile) does not allow full execution of apps in the background but limits both the time and resource usage for background applications. So you might need to solve the problem differently. Also you can't do it from inside Unity itself but you'll need to put the code in the Solution that Unity builds.

    A bunch of info about background tasks on W10(M) devices can be found here: https://docs.microsoft.com/en-us/windows/uwp/launch-resume/support-your-app-with-background-tasks
     
  3. NatsXD

    NatsXD

    Joined:
    Feb 17, 2017
    Posts:
    5
    Actually, I want my app to pause and go to background, and Windows Phone would return activity to the last opened app.
    I am trying to simulate the behaviour of the device back button.
     
  4. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    I believe Unity pauses automatically when pressing the home button on WP (and thus moving it to the background). The backbutton functionality you are talking about is definitely pre-build in the app.
     
  5. NatsXD

    NatsXD

    Joined:
    Feb 17, 2017
    Posts:
    5
    I detect whenever the user clicks on the Back Button, on Update.
    So I want some lines of code to be called that would behave like the ones I wrote before (those work for android applications).
    Maybe you know the code I need.
     
  6. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    Well, you can't directly as far as I know. You'll need to create an interop class that you can use to communicate between the Unity app and the wrapper app created on build, and then have a listener in the wrapper app that responds when the back button is pressed (I do kind of the same for a Cortana implementation I made). I do have some code here that could help you, but at the moment I don't have the time to make a gist of it. I'll try to do that later today when I am home.
     
  7. NatsXD

    NatsXD

    Joined:
    Feb 17, 2017
    Posts:
    5
    Do you have the code to make the app dormant? If you do and you can send it, I would appreciate.
    Thanks already.
     
  8. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    Not dormant per se, it does that automatically. Basically you want the back button to act like the windows button, and that is not really a problem.
     
  9. NatsXD

    NatsXD

    Joined:
    Feb 17, 2017
    Posts:
    5
    Timelog, could you post or send me the code you mentioned?
    If you know the answer for one of these questions, it would help me a lot:
    - Can I call a method that will make my application dormant (just like windows button does)?
    - Can I call a method that will open the last application in Windows Phone stack (and consequently close or suspend my app)?
    Those would be alternatives to current behaviours I can give to Back Button (do nothing and close application).
     
  10. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    802
    Anyone think he wants the code? lol.