jtth
jtth

Reputation: 886

Can HoloLens enforce a single instance of my app?

When opening an Unity app on the MSFT HoloLens it first creates a blank white box for the User to position and place via gestures. After the user has placed this white box, the application launches. The user can exit the app (but not necessarily close it) by performing the 'bloom' gesture. The app won't be running and the previously mentioned white box should re-appear (to denote this 'paused' state, as it were, between running and closed).

The issue is sometimes the app might have been exited and this white box doesn't appear. If the white box isn't present then the user can't close the application normally (by clicking the X in the top right). Likewise, if the app was exited and the user doesn't remember this when returning for their next session, they will naturally try to launch the application again. If the previous session was never actually closed it can cause issues with the newly opened session.

How do I restrict HoloLens from opening up a second instance of my Unity app, provided a session was previously opened and left either running or never closed?

Ideally if the app is already opened, when a user tries to open the app the HoloLens would refresh the previously existing instance and bring it to the users view or forcibly close the previous session before trying to open the new one (to avoid undesired behavior).

Is the best and most reliable way to handle this by enforcing a single instance of an Unity app on HoloLens? Or to detect if an instance is open and close that instance before trying to open the app again? Which, if either, is preferred or is it up to preference?

External resources I have found on this topic (a few of many):
How to determine if app is running on HoloLens - most relevant source of information I have found on the topic. Unfortunately it doesn't go into what to do with the affirmation that the app is open. Unity Script Reference - WSA (Windows Store app) - again doesn't mention enforcing single running instance
Unity Script Reference - OnApplicationQuit - not sure if this is applicable to the situation but, there is a method Unity "sends to all game objects before the application is quit".

WIP:

    private void App_Resuming(Object sender, Object e)
    {
        if (UnityEngine.VR.VRSettings.loadedDeviceName.Equals("HoloLens"))
        {
            UnityEngine.VR.VRDevice.SetTrackingSpaceType(UnityEngine.VR.TrackingSpaceType.Stationary);
            UnityEngine.VR.InputTracking.Recenter();
            UnityEngine.VR.VRDevice.SetTrackingSpaceType(UnityEngine.VR.TrackingSpaceType.RoomScale);
        }
    }

In the Initialize method (inside of 'App.cs')

    public virtual void Initialize(CoreApplicationView applicationView)

Add

    CoreApplication.Resuming += App_Resuming;

Can't test this at the moment as Hololens will connect to an network and spit out "No internet, connected" (tried both protected/unprotected networks). Device possibly needs an update, but we can't check for updates without a network connection.

Upvotes: 0

Views: 1325

Answers (1)

Kelso Sharp
Kelso Sharp

Reputation: 972

For clarification, this is not a hololens specific question, where you need to look is in the windows 10 sdk, in windows 8 it was called tombstoning, its the act of moving away from an application without closing and being able to resume, Here is a link to an article about maintaining state in a windows 10 application, it's too long of a discussion and explanation to do it justice here.

https://visualstudiomagazine.com/articles/2015/09/01/its-universal.aspx

https://learn.microsoft.com/en-us/windows/uwp/launch-resume/app-lifecycle#app-execution-state

Upvotes: 1

Related Questions