So I ran across some bizarre behavior.
I am an the first page with a ViewModel. The ViewModel only contains a ObservableCollection. When I navigate on the second page everything seems fine. But when I suspend the app on this page, the app crashes. Long-Press Back-Button or Windows Key. The bizarre thing is, that this only happens when I am not debugging. When I am debugging everything works find. Suspend-Resume works perfectly.
I could reproduce it on my Lumia 920 and the Emulator.
I kinda found the cause which is responsible for this behavior, but it should be a cause actually.
When I navigate away, I am calling this method
Frame.Navigate(typeof(SecondPage), FirstPageViewModel); //names are fictive
The cause of the weird behavior is the ObservableCollection. If I just pass a string object it is fine. If I create a local List and pass it, it crashes on Suspending.
I am thinking, I am unable to pass a List object, which does not make any sense though. Why does it not happen in Debugger. Is it possible I run out of memory somehow somewhere?
The issue doesn't concern debug mode, because while debugging, the Suspending event is not raised, so your app works fine.
To better see what is happening, invoke the suspending event manually (see answer at the link above). Then you will be able to see in debug mode, where the exception (and its kind) is thrown.
I cannot say what exacly causes the problem (without seeing the code), but you have provided one line which can be troublesome:
You navigate here and pass an object, so probably somewhere you retrive it. Look that when you are resuming your app, the page is restored, but your object normally is not. You will have to use some NavigationHelper's methods - SaveState/LoadState to save/load your passed data or handle this yourself.
If you're using the builtin
SuspensionManager
class, you can only pass "simple" types (string, char, numeric, GUID) as the second argument toFrame.Navigate()
. See the documentation forFrame.Navigate
for more info.