locked
Input needed on using background task RRS feed

  • Question

  • I have read info about background tasks given here but some things remains unclear to me.

    My app calls a server API using HTTP post/get to retrieve new items available and then lists such items in a GridView. The app uses classes and objects to handle viewmodel, server API and so on. The whole app logic could basically be compared with updating a Facebook feed.

    Now, I would like to provide the app with a background task to be executed periodically when e.g the app is suspended, the task should check for new server items and in such case notify the user with a toast or a tile update.

    Is it possible to run such a task periodically which access the app's EXISTING classes and data models for view model and server API? Whould setup could be used here?

    Monday, January 20, 2014 2:56 PM

Answers

  • Yes. If you need to pass data between the main app and the background task you can use application data or settings.
    • Marked as answer by Southbranch Monday, January 20, 2014 6:07 PM
    Monday, January 20, 2014 4:09 PM
    Moderator

All replies

  • Yes, you can share code on this. The background task is built in a separate project, but you can build a common library or link source files.

    If you control the server a better option would be to push the notifications from there rather than pulling them from a background task.

    --Rob

    Monday, January 20, 2014 3:06 PM
    Moderator
  • I am afraid we don't control the server so the push alernative is not an option.

    I assume you mean putting the background task in a separate project and share classes via Add-As-Link in VS? Ok, but perhaps I missed something. How would I handle a scenario like this: user starts the app in foreground and downloads and read current server items. Then he puts the app in suspended mode. Later the background task trigs and calls the server API but even if the task shares code logic from the app's classes, there is no way for the taks to know which item is the newest to notify the user with since the same instances of the classes (status) are not shared...? Does it mean I would need to read/write such status info in e.g. a file, Application Storage etc?

    Monday, January 20, 2014 3:29 PM
  • Yes. If you need to pass data between the main app and the background task you can use application data or settings.
    • Marked as answer by Southbranch Monday, January 20, 2014 6:07 PM
    Monday, January 20, 2014 4:09 PM
    Moderator