Over a million developers have joined DZone.

When Should You Check That Your App Has the Latest Data?

· Java Zone

Navigate the Maze of the End-User Experience and pick up this APM Essential guide, brought to you in partnership with CA Technologies

This post was inspired by a question on Stack Overflow:

What a great question: When should you update data on the client to ensure that it's always up to date for the person using the app?

Unfortunately, there is no absolute answer to this question that will cover all scenarios for everybody.

It's easiest to handle this situation if price changes happen on a predictable basis, such as overnight or at certain times, and/or on certain days of the week.

If we know that prices only change at certain times of day (or week) we can limit unnecessary network traffic (and therefore delays in using the app) by just checking if we haven't checked since the last time that prices may have changed.

If building an app using Silverlight technologies (which will be the case if targeting 7.X, 8.0 & possibly 8.1) then you should check on app start up when either the Launching or Activated events are fired.

Of course the price may be changed while the app is in use. In this situation you could send a push notification to the app while it is running to tell it to update the data. You may also need to handle the situation where a purchase is attempted but such a notification hasn't been received or yet been acted upon. More on that below.

It is not possible to send a message to such an app when it is not running to have it automatically trigger getting the latest data.

If you want to check in the background (when the app is not running) then you'll need to use a Periodic Background Agent which can download the latest data ready for when the app is next used.

If building an app for Windows Phone 8.1 and using the new application framework (i.e. not Silverlight) then it is possible to trigger a background task to download the latest data from a notification message. You may also want to trigger checking on device starting in case any notifications were missed when the device was not on. On app start-up you should check for the latest data after an activated or resuming event to check when navigating to (starting) the app.

With any of the above techniques, you can't be sure that the app will have received a message to notify it to update the data, or run the background task to check for the latest data or even been able to get to the server to get the latest data when the app is not running. This is why it makes sense to check on start-up in addition to any checking that is done in the background.

Ultimately, if the price can be changed at any time and the latest price must be used/honored, it will be necessary to check that the values which are being used on the client with the latest server prices and products when a purchase is actually made. (In reality you'll probably be checking this anyway to make sure that a product that is discontinued or out of stock is not being ordered.) 

This should be in addition to any other work that is done to synchronize data at other times.

Thrive in the application economy with an APM model that is strategic. Be E.P.I.C. with CA APM.  Brought to you in partnership with CA Technologies.


Published at DZone with permission of Matt Lacey, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}