Can I trigger sleeping background trigger from secondary tile of UWP app?

235 views Asked by At

I have this code for creation of secondary tile:

var logo = new Uri( "ms-appx:///Assets/Square150x150Logo.png" );
var tile = new SecondaryTile( "TileID", "Tile Text", "ActivateChange", logo, TileSize.Default );
await tile.RequestCreateAsync();

then I have code in my App's OnLaunched(LaunchActivatedEventArgs args) for checking if App was launched with "ActivateChange" arguments:

protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
    if (!string.IsNullOrEmpty(args.Arguments) && args.Arguments == "ActivateChange")
    {
        //Doing some work
        this.Exit();
        return;
    }
...

The problem is that when I click on secondary tile then splash screen appears, after it dissappears then it does some of my work and after that it exits the app.

What I would like for it to do is that when I click on secondary tile it will trigger some background task asociated with my App and this background task will do some of my work and then changes its state to sleeping or exits. I don't know how they work. I just know that I can have background task that is running all the time and triggers periodically on some time. But can I have background task that is somehow sleeping and can be triggered from secondary tile?

Thanks!

1

There are 1 answers

1
Damir Arh On

Live tiles are only meant for starting the app. The only difference between the primary and the secondary tile is that the secondary tile can pass an additional launch argument to the application, and you are already taking advantage of that.

In my opinion, it would be a strange experience for the user anyhow, if nothing seemed to happen when he clicked on the tile. Well, even having the application automatically quit when clicking on the secondary tile (as you are doing it now) is a strange behavior, akin to application crashing unless the user knows better.

It's difficult to suggest an appropriate alternative without knowing what you are trying to achieve. There is no way to trigger a background task by a user action from outside the application. You could use the ApplicationTrigger inside the app instead of doing the work directly which would allow you to close the app sooner. You can also look at the complete list of available triggers - it's all the classes ending in Trigger on the linked page. Maybe there's one there that would work better for you.