"Win 10 app development" app pre-boot

Source: Internet
Author: User

The so-called pre-launch, in fact, you see the name to know what the meaning, this is a direct translation, and can not find a more concise word than the term. If the system resources allow (for example, the battery is sufficient and there is enough memory space), the system will start the user's favorite application in the background, but will not display the user interface. At pre-boot, some data can be initialized beforehand, and when the user formally launches the application, the rendering interface becomes more efficient.

At pre-boot time, the application will still call the OnLaunched method, and the Suspending event will occur immediately after the OnLaunched method call, and then the application will be paused.

The OnLaunched method is also called when the user formally launches the app, so how do you know if the application is officially started or pre-launched? The parameters of the OnLaunched method have a Prelaunchactivated property, a Boolean type, and if this property is true, the current call is pre-boot; Therefore, when dealing with the OnLaunched method, it is only possible to judge this property, and when it is false, the user interface is created.

The default generated template code for your app project is this:

        protected Override voidOnLaunched (Launchactivatedeventargs e) {Frame rootframe= Window.Current.Content asFrame; //do not repeat application initialization when the window already contains content.//just make sure the window is active            if(Rootframe = =NULL)            {                //Create a frame to act as the navigation context and navigate to the first pageRootframe =NewFrame (); Rootframe.navigationfailed+=onnavigationfailed; //Place the frame in the current windowWindow.Current.Content =Rootframe; }            if(e.prelaunchactivated = =false)            {                if(Rootframe.content = =NULL)                {                    //When the navigation stack has not been restored, navigate to the first page,//and configure it by passing in the required information as a navigation parameter//ParametersRootframe.navigate (typeof(MainPage), e.arguments); }                //Make sure the current window is activeWindow.Current.Activate (); }        }

It is the Frame object that is instantiated as the root of the UI, and then determines whether it is a pre-boot, or, if not, navigates to the main page.

We can simply modify this:

        protected Override voidOnLaunched (Launchactivatedeventargs e) {if(!e.prelaunchactivated) {Frame rootvisual= Window.Current.Content asFrame; if(RootVisual = =NULL) {rootvisual=NewFrame (); Window.Current.Content=rootvisual; }                if(Rootvisual.content = =NULL) {rootvisual.navigate (typeof(MainPage), e.arguments);            } Window.Current.Activate (); }        }

Don't create a UI anyway, get a frame there is nothing to use, so just wait until the formal start to create a frame.

OK, now everybody knows how to judge the pre-boot, then, if I want to debug pre-boot, what to do. To debug a pre-boot, do not run debugging directly, as the direct run is to enter the formal startup mode instead of pre-boot.

The correct action is to execute the menu "Debug"-"Debug other Targets"-"Debug Universal Windows App pre-boot", then execute the OnLaunched method, and the Prelaunchactivated property will return true.

During debugging, the app does not raise the Suspending event, and you can control the app's entry into the Suspend state through the Debug Location toolbar.

OK, this article is really too simple, in order to save time, here to omit 310 words ... This article concludes.

"Win 10 app development" app pre-boot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.