我目前正在尝试向我的应用添加一个扩展的启动画面,一旦完成下载RSS源并在该Feed中找到有效的高分辨率图像,就会自动删除它自己的缩略图(在第一次启动时)应用程序,这可能需要5秒以上,让用户留下空白屏幕)。
不幸的是,MSDN Extended Splash Screen示例并不是很有用,因为他们通过按下按钮而不是等待各种嵌套函数完成来解雇他们。我发现的其他示例跳过重要的细节,这对于对应用程序编程相对较新的人没有帮助。
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// TODO: This application has been newly launched. Initialize
// your application here.
} else {
// TODO: This application has been reactivated from suspension.
// Restore application state here.
}
performSetupTasks();
// Retrieve splash screen object.
var splash = args.detail.splashScreen;
// Display the extended splash screen.
displayExtendedSplash(splash);
args.setPromise(WinJS.UI.processAll().then(removeExtendedSplash()));
}
};
相反,上面的代码会立即删除扩展的启动画面;我需要在报告performSetupTasks()
的代码中添加任何内容吗?
答案 0 :(得分:1)
问题是您可能正在使用performSetupTasks();
方法执行异步操作。
重构您的代码以返回该承诺,因此只有在履行承诺后才会删除启动画面:
function removeExtendedSplash() {
var promise = WinJS.xhr(...);
promise.then(function(result) { ... });
return promise;
}
args.setPromise(removeExtendedSplash());
您还可以尝试这种扩展的启动画面实现:https://gist.github.com/petertakacs/5330117
答案 1 :(得分:0)
在进入应用程序之前暂停启动画面显示的脚本...
1。)“app.onactivated = function(args){ if(args.detail.kind === activation.ActivationKind.launch){“在default.js中添加以下代码
pauseDisplayOfSplashScreen(2500);
2.)在app.oncheckpoint = function(args)之上,添加以下功能。
function pauseDisplayOfSplashScreen(milliseconds) {
milliseconds += new Date().getTime();
while (new Date() < milliseconds) { }
}
为了清楚地理解这里是完整的启动画面暂停工作default.js:
// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232509
(function () {
"use strict";
WinJS.Binding.optimizeBindingReferences = true;
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
//pause for two seconds
pauseDisplayOfSplashScreen(2500);
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// TODO: This application has been newly launched. Initialize
// your application here.
} else {
// TODO: This application has been reactivated from suspension.
// Restore application state here.
}
args.setPromise(WinJS.UI.processAll());
}
};
function pauseDisplayOfSplashScreen(milliseconds) {
milliseconds += new Date().getTime();
while (new Date() < milliseconds) { }
}
app.oncheckpoint = function (args) {
// TODO: This application is about to be suspended. Save any state
// that needs to persist across suspensions here. You might use the
// WinJS.Application.sessionState object, which is automatically
// saved and restored across suspension. If you need to complete an
// asynchronous operation before your application is suspended, call
// args.setPromise().
};
app.start();
})();
希望这能解决您的问题:)