Search code examples
c#windows-phoneresumesuspend

Windows Phone App Restarts instead of Resumes although it Appears in Task List


Controlling suspending, resuming and starting Windows Phone Apps with Windows RT, there are 3 events: OnLaunching -> OnLaunched respectively OnSuspending OnResuming

Normally if an app launches, OnLaunching is fired. When the app suspends e.g. the screen saver comes up, OnSuspending is fired. If I go back to the app by opening task list, OnResuming is fired.

Now I have the following problem.

If I switch to another app or the screen saver appears, OnSuspending is fired - this is OK. But if I go back to my app via task list after about 15-20 minutes, the OnLaunching event is fired instead of OnResuming, although my app appears still in the task list.

It's like the app is newly started !

This happens since I redesigned the app in Windows 8.1 RT. In the earlier version of my app, which was running in Silverlight, this worked fine. Whenever I went back to my app via task list, OnResuming was fired.

Doing some tests, I found out the following: Launching an app, the previous execution state can be read from the ActivateEventArgs. So I read them out to see, what application status was before launching. After starting the app the first time, its state is 'notRunning'. If I close the app and reopen it, the state is 'closedByUser'. If the app has been suspended and I revoke it after 15-20 minutes, the state is 'terminated'.

However, the state 'terminated' means, the windows has been closed the app.

Why does windows close my app already after 15-20 minutes and why the app is still in the task list if it has been closed ?

Do you have an idea, what the problem is ?


Solution

  • I was told by Microsoft: The OS can terminate an app in order to free up resources. But such an up can still appear in the task bar. If the suspended app was terminated, there is no Resuming event and instead OnLaunched() is called with an ApplicationExecutionState of Terminated. So, the routines to restore the app state must be called within OnLaunched().

    Sometimes it's required to distinguish if the app has been relaunched by tasklist or by tile. For this, use the TileId property in the OnLaunched(). TileId is "App" if the app has been started by tile and it is empty if the app has been relaunched by tasklist. TileId could also have another value if you generate eg. a second tile for the app giving them another id.

    However, this does not work in Windows 8.1 as the value of TileId is always "App" independent of starting it by tasklist or standard tile.