Does OnNavigatedTo get called when you turn on the screen and the app comes to life?

做~自己de王妃 提交于 2020-01-17 02:23:23

问题


I'm dealing with a strange situation I want to debug in my Windows Phone 8.1 app, and I'm not sure in which moments OnNavigatedTo is called.

Obviously, it gets called (and I've checked tracing it with the debugger) when you navigate to the view normally.

My doubt arises in other point I want to check, let's call it "You wake up your application and the screen was shut off".

My question is: When you turn on the screen, and you swype the screen protector away, is "OnNavigatedTo" function called or not?

According to some manuals I've read somewhere else, it should.

According to my Debug.Writeline traces, it seems it doesn't.

I need to check some condition and execute some code before/when the view appears, and I'm unable to do it properly.

PS: Does it exist some other alternative event I should use to deal with "This view is becoming visible/focused after you turn the screen on" situation instead of "OnNavigatedTo" ?

Thanks in advance.


回答1:


In Windows Phone 8.1 Runtime (Store apps) OnNavigatedTo is called only during navigation. It's not called after resuming from suspension - you can read a reference here at MSDN:

before Suspending event, the OnNavigatedFrom event is being called, but when you Resume, the OnNavigatedTo is not called

In your case when you lock the screen, the app is suspended, after you resume OnNavigatedTo is not called. If you look for some events which may be called - take a look at Window.Activated and Window.VisibilityChanged events.

The other case is that when you debug your app, your app won't be suspended, you will need to test it via Lifecycle events tab.



来源:https://stackoverflow.com/questions/29412402/does-onnavigatedto-get-called-when-you-turn-on-the-screen-and-the-app-comes-to-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!