Activation and suspension of Windows 8 applications

Source: Internet
Author: User
Application Program Activation and suspension examples demonstrate how you handle activation, suspension, recovery, and your Metro style applications. ( Function (){
VaR Order = 0;
VaR APP = winjs. Application;
VaR Myfile = "myfile. Text ";
Sdksample. scenarioselection = False ;

function onscenariochanged () {
/// do any necessary clean up on the output, the scenario id
/// can be obtained from sdksample. scenarioid.
sdksample. displaystatus ("");

If (sdksample. scenarioid = 1) {
document. getelementbyid ('scenario1outputtextarea '). style. display = 'block';
}< br> If (sdksample. scenarioid = 2) {
document. getelementbyid ('scenario1outputtextarea '). style. display = 'none';
}< BR >}

FunctionDomcontentloadedhandler (){
Document. getelementbyid ("scenarios"). addeventlistener ("change ",/*@ Static_cast (eventlistener)*/Onscenariochanged,False);

Order + = 1;
Document. getelementbyid ("scenario1output"). innerhtml + = "domcontentloaded was triggered at order:" +/*@ Static_cast (string)*/Order + ".";
}

function loadhandler () {
order + = 1;
document. getelementbyid ("scenario1output "). innerhtml + = "
load was triggered at order:" + /* @ static_cast (string) */ order + ". ";
}

function activatedhandler (eventargs) {
order + = 1;
document. getelementbyid ("scenario1output "). innerhtml + = "
activated was triggered at order:" + /* @ static_cast (string) */ order + ". ";

If(Eventargs. Kind === windows. ApplicationModel. Activation. activationkind. Launch ){
Sdksample. selectscenario ("1 ");
Document. getelementbyid ('scenario1outputtextarea '). style. Display = 'block ';

// Check if the activatedreason means that this is a re-activation after a suspension followed by a graceful
// Termination. If it is then we must have saved the state in suspending handler. Retrieve the persisted state.
VaR Activatedreason = eventargs. previusexecutionstate;
If (Activatedreason === windows. ApplicationModel. Activation. applicationexecutionstate. Terminated ){

// If there is going to be some Asynchronous Operation done during activation then
// The app can signal the need to handle activation of the application asynchronously.
// To do so the app can use the getdeferral method.
VaR Deferral = eventargs. activatedoperation. getdeferral ();

//Populate the text box with the previusly saved value
App. Local. readtext (myfile, "default"). Then (Function(STR ){
Document. getelementbyid ("usertext"). value = STR;

// After the asynchronous operation is done the app must call complete on the deferral object
// As follows else the app wocould get terminated.
Deferral. Complete ();
});
}
}

If(Eventargs. Kind === windows. ApplicationModel. Activation. activationkind. Protocol ){
Sdksample. selectscenario ("2 ");
Document. getelementbyid ('scenario1outputtextarea '). style. Display = 'none ';

// This is a protocol activation.
// Protocol format currently supported in this sample is: sdksampleprotocol: domain? Src = [some url]
Document. getelementbyid ("scenario2output"). innerhtml + = "this is protocol activation .";
Document. getelementbyid ("scenario2output"). innerhtml + = "<br/> protocol format used for this activation:" +
Eventargs. Uri. rawuri + "<br/> ";
}

// If (eventargs. Kind === windows. ApplicationModel. Activation. activationkind. Search ){
// // Noop
// } Else if (eventargs. Kind === windows. ApplicationModel. Activation. activationkind. sharetarget ){
// // Noop
// } Else if (eventargs. Kind === windows. ApplicationModel. Activation. activationkind. sendtarget ){
// // Noop
// } Else if (eventargs. Kind === windows. ApplicationModel. Activation. activationkind. File ){
// // Noop
// } Else if (eventargs. Kind === windows. ApplicationModel. Activation. activationkind. filepicker ){
// // Noop
// } Else if (eventargs. Kind === windows. ApplicationModel. Activation. activationkind. contactpicker ){
// // Noop
// } Else if (eventargs. Kind === windows. ApplicationModel. Activation. activationkind. Device ){
// // Noop
// } Else if (eventargs. Kind === windows. ApplicationModel. Activation. activationkind. printtasksettings ){
// // Noop
// } Else {// If (eventargs. Kind = windows. ApplicationModel. Activation. activationkind. camerasettings)
// // Noop
// }
}

Function Suspendinghandler (eventargs ){
// If there is going to be some Asynchronous Operation done during suspension then
// The app can signal the need to handle suspension of the application asynchronously.
// To do so the app can use the getdeferral method.
VaR Deferral = eventargs. suspendingoperation. getdeferral ();

// This is only for advanced scenarios when using a file is necessary to persist data.
App. Local. writetext (myfile, document. getelementbyid ("usertext"). Value). Then ( Function (){
// After the asynchronous operation is done the app must call complete on the deferral object
// As follows else the app wocould get terminated.
Deferral. Complete ();
});
}

FunctionResuminghandler (){
}

Document. addeventlistener ("domcontentloaded", domcontentloadedhandler,False);
Window. addeventlistener ("LOAD ",/*@ Static_cast (eventlistener)*/Loadhandler,False);
Windows. UI. webui. webuiapplication. addeventlistener ("activated", activatedhandler,False);
Windows. UI. webui. webuiapplication. addeventlistener ("suspending", suspendinghandler,False);
Windows. UI. webui. webuiapplication. addeventlistener ("resuming", resuminghandler,False);

})();

 

Complete example

/files/risk/windows8/APP activation sample.rar

Related Article

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.