locked
How to on click toasts notifications no launch Metro app?

All replies

  • Hi Hot,

    1.  This is the fundamental purpose of Toasts, you cannot disable this: http://msdn.microsoft.com/en-us/library/windows/apps/hh465385.aspx#toast_notifications

    2.  II am pretty sure you can do this.  What code are you using?  When you step through in the debugger, do all your lines of code execute properly?

    -Jeff


    Jeff Sanders (MSFT)
    Wednesday, December 21, 2011 1:06 PM
    Moderator
  • I use javascript, I add code to BackgroundTaskSample's background.js. I don't how to debug to this file.

    code as:

    (function() {
    "use strict";

    var notifications = Windows.UI.Notifications;

    //
    // The background task instance's activation parameters are available via Windows.UI.WebUI.WebUIApplication.backgroundTask
    //
    var cancel = false,

    progress = 0,

    backgroundTask= Windows.UI.WebUI.WebUIApplication.backgroundTask;

    console.log("Background " + backgroundTask.taskInstance.task.name + " Starting...");

    //
    // Associate a cancellation handler with the background task.
    //
    function onCanceled(cancelSender, cancelReason) {
    cancel = true;
    }

    backgroundTask.taskInstance.addEventListener("canceled", onCanceled);

    //
    // This function is set to run every 1000 milliseconds ten times and perform background task activity.
    //
    function onTimer() {
    var key = null,
    settings= Windows.Storage.ApplicationData.current.localSettings;

    if (!cancel) {
    if (progress < 100) {
    //
    // Simulate work being done.
    //
    setTimeout(onTimer, 1000);

    //
    // Indicate progress to the foreground application.
    //
    backgroundTask.taskInstance.progress = progress;
    progress += 10;
    } else {
    var notificationManager = notifications.ToastNotificationManager;
    var toastXml = notificationManager.getTemplateContent(notifications.ToastTemplateType.toastText01);
    var textNodes = toastXml.getElementsByTagName("text");
    textNodes[0].appendChild(toastXml.createTextNode("A toast!"));
    sdkSample.displayStatus(toastXml.getXml());
    var toast = new notifications.ToastNotification(toastXml);
    notificationManager.createToastNotifier().show(toast);

    //
    // Use the success property to indicate that this background task completed successfully.
    //
    backgroundTask.success = true;

    backgroundTask.taskInstance.progress = progress;

    console.log("Background " + backgroundTask.taskInstance.task.name + " Completed");

    //
    // Write to localSettings to indicate that this background task completed.
    //
    key = backgroundTask.taskInstance.task.taskId.toString();

    settings.values[key] = "Completed";

    //
    // A JavaScript background task must call close when it is done.
    //
    close();
    }
    } else {

    //
    // If the cancellation handler indicated that the task was canceled, stop the background task.
    //
    console.log("Background " + backgroundTask.taskInstance.task.name + " Canceled");

     

    backgroundTask.success = false;

     

    key = backgroundTask.taskInstance.task.taskId.toString();

     

    settings.values[key] = "Canceled";

    close();

    }

    }


    //
    // Start the timer function to simulate background task work.
    //

    setTimeout(onTimer, 1000);

    })();

    Thursday, December 22, 2011 2:01 AM
  • Hi Hot,

    On the surface your code looks ok.  Does the same code work OK in the main application?  Did you enable Toasts in your manifest (Application UI tab)?

    -Jeff


    Jeff Sanders (MSFT)
    Thursday, December 22, 2011 2:07 PM
    Moderator
  • Hi jpsanders,

    thanks for reply.

    yes, same code work OK in the main application, It is enable Toasts in manifest (Application UI tab).

    Friday, December 23, 2011 2:02 AM
  • Hi Hot,

    You will need to step through this in the debugger and see what is failing.

    I suspect this is the line however: sdkSample.displayStatus(toastXml.getXml());

    -Jeff


    Jeff Sanders (MSFT)
    Tuesday, December 27, 2011 7:30 PM
    Moderator
  • I don't know debug this information? can you tell me detailed steps?

    thanks!

    Thursday, December 29, 2011 4:30 AM
  • Sorry Hot, I missed this.  Did you get this debugged and resolved?
    Jeff Sanders (MSFT)
    Wednesday, January 25, 2012 6:15 PM
    Moderator
  • I still don't resolved!
    Thursday, February 02, 2012 8:57 AM
  • It is fairly easy to debug your background task and you will need to do this to get the root of the problem:

    Load your project.

    Right click on your project in the solution explorer, choose Properties from the context menu and click onDebugging. Change Launch Application to No.

    Then hit start the debugger by hitting F5 (or however you want)...

    Put a BP on the code that you want to debug.  When your Background task hits that BP it will break into the debugger.

    -Jeff


    Jeff Sanders (MSFT)
    Thursday, February 02, 2012 7:33 PM
    Moderator