Event on returning to app, after exiting by Windows key [UWP][Win10 Mobile]

狂风中的少年 提交于 2019-12-10 12:16:04

问题


I have big trouble finding right event for me - user during browsing files in my app [UWP Windows 10 Mobile app] can tap on it and then I launch it in default app by

Windows.System.Launcher.LaunchFileAsync

my app is 'minimzed' (just like by pressing Windows key) and user can interact with file in whatever app he wants. Now by pressing back-key he is returning to my app. Do you know any event which is trigerred now? I want to update the file (if it was changed) but I cannot find any event to check it.


回答1:


Take a look at App lifecycle, I think you should register event handler for both OnLaunched and Resuming, one for switching back from terminated state, another for from suspended state.

When the user switches back to a suspended app that has been terminated, the app should restore its application data in its OnLaunched method.

If an app registered an event handler for the Application.Resuming event, it is called when the app is resumed from the Suspended state. You can refresh your app content and data using this event handler.




回答2:


It is important to understand the UWP app lifecycle. If you want to have control on what is happening while application is Launched first time, Suspended or Resumed you should refer to below guideline:

https://msdn.microsoft.com/en-us/windows/uwp/launch-resume/app-lifecycle

Also in the App.xaml.cs file you can manage this cycle. For instance you can control what to do when application is Resumed from the background:

    public App()
    {
        this.InitializeComponent();
        this.Suspending += OnSuspending;
        this.Resuming += App_Resuming;
    }

    private void App_Resuming(object sender, object e)
    {
       //Code to execute while resuming the app...
    }


来源:https://stackoverflow.com/questions/35493754/event-on-returning-to-app-after-exiting-by-windows-key-uwpwin10-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!