HoloLens 2 / Unity / App Lifecycle : Handling Resuming

tfcmad 21 Reputation points
2022-08-15T08:20:25.147+00:00

When a HoloLens 2 app is closed by the user it will go into a Suspended state as per the Documention, I would like to perform some actions such as checking the network connectivity when the app is Resumed.

How can this be handled or detected? is there an event that is triggered when the app is Resumed?

In a normal UWP I could do something like:

partial class MainPage  
{  
   public MainPage()  
   {  
      InitializeComponent();  
      Application.Current.Resuming += new EventHandler<Object>(App_Resuming);  
   }  
  
    private void App_Resuming(Object sender, Object e)  
    {  
        // TODO: Do Something  
    }  
}  

Thanks

HoloLens Development
HoloLens Development
HoloLens: A family of Microsoft self-contained, holographic devices that enable engagement with digital content and interaction with holograms in the surrounding environment.Development: The process of researching, productizing, and refining new or existing technologies.
390 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. clcheles 271 Reputation points
    2022-08-15T10:22:54.853+00:00

    In some scenarios, the app is not truly suspended in the UWP app model sense. Unity has this method: MonoBehaviour.OnApplicationPause(bool) that retrieves the status when app pauses.

         private void OnApplicationPause(bool pause)  
            {  
                if (pause)  
                {  
                    DoSomething();  
                }  
                else  
                {  
                    DoSomethingElse();  
                }  
            }  
    

    Take a look at this sample
    Depending on your scenario, you might also want to check the project setting under the UWP section for "Run in background". It should be enabled by default, but if not, Unity might force suspend the app to avoid rendering frames that can't be seen, hence save some battery.

    If this answers your question, I'll post it here too

    0 comments No comments