I'm seeing some unexpected things happening in the emulator.
When debugging and starting the app for the first time, the Application_Launching fires just fine. When clicking the start button, the Application_Deactivated event fires fine. When click the back button, the Application_Activated event fires fine.
If I click the start button then go to my apps and launch my app, no events are fired. I would assume either the Application_Launching or Application_Activated would fire when the app is launched every time, just a different event depending on how the app got there.
Is this an issue with the emulator or do I have the wrong assumptions here?
Well, the events get fired right. What you missed is that debugger get dettached when you are launching "new instance" of your app. ;)
Related
If I close my app with the back-button, the event Application_Closing is raised and the code is executing.
When I close my app in the list with active apps, no event is raised...
I really need an event for this.
Does anyone know a solution?
There is no event to detect when your app is terminating from the app list. When your app goes to background it will be tombstoned.
You can react on this with the Application_Deactivated event. So you should handle both events Application_Deactivated and Application_Closing.
Learn more about the app's lifecycle here.
I got a problem with jPlayer.
When the page loaded, the player plays automatically but it doesn't trigger "play" event.
Only when I click on pause button and click on play button again, the event is triggered.
Is that a bug of jPlayer?
hard to say since you don't mention which browser you are experiencing this in but my experience is that it is safer to rely on the 'playing' event rather than the 'play' event. Ideally the 'play' event is to be fired as soon as you call jPlayer('play') and 'playing' then is fired once the actual playback starts (i.e. after initial buffering etc). What I've seen this works fine in Safari but does not work in Chrome, in Chrome the two events are both fired when content starts to play.
I have a question about the expected behavior of Window Phone 7.5 emulator.
If I deactivate (start button), close (back button from first screen) or tombstone my data (selecting this option in VS first and then in the emulator clicking start button), and then press Stop Debugging (Shift+F5) in VS, all changed data in my app for that session is retained when I start the debug process again (F5).
However, when I just changed data in my app in the emulator and don't actively deactivate, close or tombstone my app, and then press Stop Debugging (Shift+F5) and then Start Debugging (F5) the changed data is not retained. I've noticed that upon stopping debugging, neither the Application_Deactivated or Application_Closing occur as well.
Is this expected behavior when starting/stopping the debugging processes? I'm asking because I need to know if this has any effect in the real world, like for example if I'm in my app and make a change and then someone turns off the phone completely right then and there and turns it back on, will my data be retained
This is expected. What you are doing is effectively crashing your app. If the phone/app is shut down in a normal situation then Deactivated or Closing will be invoked.
I am facing some issues in WP7 tombstoning. My issue is application hangs when i try for a sudden tombstone and come back. ie, After loading the page i press device menu button and with in seconds i pressed back button( Pressed Back button before the actual page disappeared) In that time the page loads but the application hangs / its back key press is not working. and if we try for a slow thombstone it is working perfectly. And the pretty interesting thing is that, while tombstoning the loaded and unloaded events of APP working perfectly. Please any one help me to solve this issue.
It sounds like your App has been deactivated, but not tombstoned. This results in neither the App or Page contrusctor being called, causing your app to act in unexpected ways. I highly recommend reading the Windows Phone Silverlight Application Life Cycle document. The relevant extract for said article:
This case can occur if the user
presses the Start and Back buttons on
the phone in quick succession. In this
case, the application received a
Deactivate event and the system was
starting to save the state of the
application to perform an application
tombstone. Before this operation is
completed, the app Activated event is
received. The system knows that the
application was not removed from
memory, so the flow of execution is
different. Specifically:
• The app constructor is not called.
• The page constructor is not called.
The only way for the application to determine
if this condition has occurred is to
set a flag to indicate if the page
constructor has been called. If you
notice in the above section, this flag
was set in the page constructor, and
cleared in the OnNavigateFrom event.
In this case, we will receive the
OnNavigatedTo event, but we will see
that the page constructor was not
called. This tells us that our
application was not tombstoned.
I am attempting to handle the loss of focus of my application, either by a phone call or other event, and also by the pressing of the home key.
I have tried setting a flag in the OnNavigatingFrom/OnNavigatedFrom and OnNavigatedTo event handlers but each time the app starts (either after pressing home, or something else) it always seems to be resetting the flag.
Which are the correct events I should be using in order to correctly "pause" and subsequently "resume" my application if it loses focus?
You should read the documentation about application lifecycle.
When you press the Home button, or when you receive a phone call, the application is paused.
If you pressed Home, you can then restore the application by pressing the back button.
to handle these events, in App.xaml.cs by default the methods are: Application_Activated and Application_Deactivated
Of course you can manage to store data before the pause, and restore it when application is restored.
This is called tombstoning.
What you need is described in the following links:
http://windowsphone7.vectorform.com/2010/11/16/wp7-application-lifecycle/
http://www.windowsphonegeek.com/articles/WP7-Application-Lifecycle-and-Tombstoning
Read this. This is a microsoft tutorial on how to save state.
It'll give you how to save your ApplicationData when it is tombstoned.
Basically edit the Application_Closing and Application_Activated methods in the App.xaml to save the data to the system using isolated storage.