When I am running the application and press the start button, the program runs the deactivated event, and If I back to the game, it runs the activated. But if then I press the start button, It doesn't runs the deactivated again. What's up?
I haven't tested it myself but it sounds like your event handler for "Deactivated" only gets hooked once (on application startup) and not when the application is (re)activated.
Where do you register your event handlers for activated/deactivated?
I guess you've already seen it but here is a good tutorial by Shawn Wildermuth:
Tombstoning
If it doesn't work with above guidelines, could you perhaps try to hook the Deactivated event yourself from the Activated event in code behind?
void Application_Activated(object sender, ActivatedEventArgs e)
{
Deactivated += Application_Deactivated;
}
I don't think that above "hook" should be necessary though. Please post some code of how you register the events and the event handlers if you're still unsure.
HTH
Related
We are seeing a change in Outlook with one of actions (“Help”) that stopped working on the web client only.
This action simply calls a js that opens a web page in a displayDialog() but it’s uiless in the sense that there’s no pane.
The other action (“Sign”) works ok but it launches a pane that does this.
Both of them work fine on the rich client (at least the version I use).
I wonder if there has been in recent changes in the requirements or the way this works?
We’re not seeing any error messages, just nothing happens after the prompt saying that the add-in is doing something.
We did some initial testing and noticed that in chrome the dialog will sometimes appear briefly. Could you confirm that you are calling event.completed() in the eventhandler of EventType.DialogEventReceived? event.completed() must be called in the DialogEventReceived handler otherwise the dialog will be closed prematurely.
Office.context.ui.displayDialogAsync(url, dialogOptions, function(result) {
// In the callback, save the dialog object
dialog = result.value;
// Add an event handler for messages sent via messageParent
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogMessageReceived, receiveMessage);
// Add an event handler for events from the platform (like closing the dialog, etc.)
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogEventReceived, dialogClosed);
});
I have a listbox in my WP7 app, and I would like to keep/save listbox inserted items when I reload the application. I tried this, but it not work:
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
this.SaveState(e);
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.RestoreState();
}
What should I do??
In tombstoning you should look at storing application data in the PhoneApplicationService.State or IsolatedStorage.ApplicationSettings (depending on the size of the data).
The App.xaml.cs file already contains four methods to help you know when you application is 'Launching' (raised when the user initially launches the application), 'Activated' (raised when the application is dormant or tombstoned and the user navigates back to the application), 'Deactivated' (whenever the user navigates forward away from the application. Although applications are typically made dormant after they are deactivated, there is no way to know at this point whether the application will be tombstoned or terminated after this event) and 'Closing' (when the user uses the Back button to navigate backwards past the first page of your application. After this event, your application is terminated)
For more info check out : How to: Preserve and Restore Application State for Windows Phone
im developin an app for wp7 that it holds pictures and notes with password login. But when app running if user press windows button app is running at background and if user press back button it resumes without asking password again.
i tried to Navigate when app activated but i couldnt manage it in Application_Activated method. is there a way to do that? Or could you advice me sth else that solve my problem.
ty.
here is my code im using to navigate,
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
I got around this issue by using UserControls on the MainPage, showing one if the user had not yet logged in and the other if they had, I set these controls up to show/hide based on certains states in the MainPage and then bind that to the MainViewModel:
private void Application_Activated(object sender, ActivatedEventArgs e)
{
// Ensure that application state is restored appropriately
....your code here to load stuff...
App.ViewModel.MainPageState = "ShowThemTheLogin";
}
}
I am building a windows phone application (basically its a game but I am not using XNA, Silverlight was enough). The graphics are moving based on a DispatcherTimer. What I want to do is basically stop the timer whenever a call arrives on the phone, and start it again after the call has finished, so that the game state is not lost.
I tried with :
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
Game.timer.Start();
}
// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
Game.timer.Stop();
}
but it did not work, it actually does not reach to this point when a call arrives at the phone. Anyone had such experience?
Thanks in advance :)
When a call is received you will receieve the Obscured Event on the Frame.
Please note that this event can also be fired for more than just a received phone call though.
I'm looking for some app life cycle help from the wp7 experts. My app has a refresh step in a specific page but I only want to launch this when the user brings the app to life from the background.
Note- The life cycle step I'm looking for isn't called when the page is init() only when I'm navigated (back) to or the user has taken a phone call and then re-opens the app (keeping the same page open)
Thank you in advance
what you are looking for is called Tombstoning and you can find a great article at http://wildermuth.com/2010/10/17/Architecting_WP7_-_Part_5_of_10_Tombstoning
The events are:
Launching (opened from tile)
Deactivated (user takes a call or something)
Activated (back from the call)
Closing (Leaves you app via the "Back" button)
You are looking for the Activated event. These are in your App.xaml.cs/vb file. Hook into the event, and update your data model. When your page is bound to that model it will get the data.
If you are not using MVVM, and can't really refresh from that event, you can do it using the PhoneApplicationService.Current.StartupMode property. It has two options Activate (what you are looking for) and Launch (loaded fresh from the tile). It would look something like
Init()
{
if (PhoneApplicationService.Current.StartupMode == StartupMode.Activate)
{
Refresh()
}
}