Question

i would like to know if it is possible to refresh date time when the app returns from a deactivated state in WP7.5. My app is basically a calendar type and when the app starts the current day is highlighted.

So if i start the app, then press the start button, my app goes to deactivated state, then go to settings and change the time zone, naturally the date and time may change and then come back to my app, it retains the old date.

eg. Suppose current date is 20 and we change the timezone where the date is 19, ideally my app should highlight 19, but it does not. I assume that its becomes before the app goes into deactivated state, it stores all the states and when it returns, it loads the same data. Is there anyway i could refresh the datetime?

Alfah

Was it helpful?

Solution

Assuming that you have a model class that contains a DateTime field called DateToDisplayAsToday, and that model is accessible within App.XAML, you will want to to the following in App.xaml.cs

    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
        // Application_Launching fires when the app starts up.

        // retrieve any data you persisted the last time the app exited.

        // Assumes you have a local instance of your model class called model.
        model = new model(); 
    }

    private void Application_Activated(object sender, ActivatedEventArgs e)
    {
        // Application_Activated fires when you return to the foreground.
        // retrieve any data you persisted in the Application_Deactivated
        // and then you can set the current DateTime
        model.DateToDisplayAsToday = DateTime.Now;
    }

    private void Application_Deactivated(object sender, DeactivatedEventArgs e)
    {
        // persist an data you don't want to lose during tombstoning
    }

    private void Application_Closing(object sender, ClosingEventArgs e)
    {
        // persist any data you want to keep between separate executions of the app
    }

OTHER TIPS

It's been a while since I've done any WP7 development, but I'm sure there's an event raised when the app is reactivated - can't you just query DateTime.Now or DateTime.Today at that point?

EDIT: Looking at the docs, I think you want the Launching and Activated events. (Launching so that you check the time even on the initial launch; Activated for reactivation after becoming dormant.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top