4

我目前正在尝试向我的应用程序添加一个扩展的初始屏幕,一旦它完成下载 RSS 提要并在该提要中找到有效的高分辨率图像以制作缩略图,它就会自动删除(在第一次启动应用程序时,这个可能需要 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()不完整的代码中添加任何内容?

4

2 回答 2

1

问题是您可能正在您的performSetupTasks();方法中执行异步操作。

重构您的代码以返回该承诺,因此只有在该承诺完成后才会删除启动画面:

function removeExtendedSplash() {
    var promise = WinJS.xhr(...);
    promise.then(function(result) { ... });
    return promise;
}

args.setPromise(removeExtendedSplash());

你也可以试试这个扩展的闪屏实现:https ://gist.github.com/peterakacs/5330117

于 2013-04-07T12:15:14.427 回答
0

在进入应用程序之前暂停闪屏显示的脚本...</p>

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();

 })();

希望这能解决你的问题:)

于 2012-12-01T21:06:14.040 回答