Derik Whittaker

Syndication

News


Handling Resuming in your Windows 8 Applications

Windows 8 applications (aka Windows Store applications) have 3 different life cycle states they can go through:

  1. Launching
  2. Suspending
  3. Resuming

Handling both Launching and Suspending is pretty much covered out of the box but what if you need to resume from a suspended state?  In most normal scenarios you should not have to do too much here because the built in SuspensionManager (this is generated code, not framework code) will handle putting your application back together in terms of what page your user was on and how the page/screen was populated when it was suspended.

However, if you are using data which is gathered from a remote source such as a web service you may want to refresh your application when it is resuming from suspension.  But how exactly can we accomplish this?

Hooking up the Resuming Event

You need to wire up the .Resuming event inside your App.cs class.  By default the template only wires the Suspending event as it is used in almost every application.

Handling the Resuming Event

As you can see above it does take some effort to get to your underlying viewmodel in order to make the Resume() call but it is well worth it.

We first need to get the current frame.  Once we have the frame we want to check to ensure it is of the correct type in order to further check its underlying data context.  Finally we want to check out data context to ensure it is of the correct type.  Doing this final  check will safe guard us and allow us to only make the resume calls on pages which require it.

Doing something useful in our Resume() call

In the Resume() is where you would need to handle any remote data fetching or updating of existing data.

Defining our IResumable interface

Our above interface is small, but it does the trick.  It allows us to identify which pages need to be resumed and enables a way to make the call

As you can see handling the Resuming event in a Windows 8 application is not hard, however getting to your underlying data context does take a bit of work, but this work is well worth it in my opinion.

Till next time,


Posted 01-26-2013 6:43 AM by Derik Whittaker
Filed under: , , ,

[Advertisement]

Comments

MartinD wrote re: Handling Resuming in your Windows 8 Applications
on 01-27-2013 3:57 PM

Simple but useful article, thanks! I really think the framework should have included some kind of convenience class or method for grabbing the DataContext from the currently active page, just because the casting and is/as calls feel a bit naff.

Derik Whittaker wrote re: Handling Resuming in your Windows 8 Applications
on 01-27-2013 5:15 PM

@Martin,

I know, this took me a bit to figure out but really it is not all too bad.

buy social bookmarks wrote re: Handling Resuming in your Windows 8 Applications
on 03-22-2013 7:21 PM

GJ26za Looking forward to reading more. Great post.Thanks Again.

buy social bookmarks wrote re: Handling Resuming in your Windows 8 Applications
on 03-24-2013 2:51 PM

lY3BbS Thanks so much for the post.Really thank you! Want more.

comedy channel wrote re: Handling Resuming in your Windows 8 Applications
on 04-06-2013 12:51 PM

This is one awesome blog post.Really thank you! Great.

grizzly bears wrote re: Handling Resuming in your Windows 8 Applications
on 04-06-2013 1:37 PM

Hey, thanks for the article post.Thanks Again. Awesome.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)