Search code examples
windows-phone-8parse-platformbackground-agents

Background Agent ParseUser.CurrentUser not cached/accessible Windows Phone


I've implemented a (for now) simple Background Agent in my Windows Phone 8 app. In the background agent, a WebRequest is made to update a stock list stored in XML in the IsolatedStorage. In other parts of the app, during debugging, I can see the currently logged in user; however, when the BackgroundAgent launches, the CurrentUser is null. At this point, shouldn't the CurrentUser be cached in the application? It seems to be cached for one part of the app (the main app) but uncached/unacceptable in others (the background agent).The current user seems to never be set in my Background Agent. I'm willing to provide more information, but does anyone know if this is a bug, or an implementation error?

PROBLEM: CurrentUser always set to null in BackgroundAgent. Are the sessions different in the BackgroundAgent from the main project (which is why it is never set)? Any help is appreciated.


Solution

  • Background Agents and Foreground Apps have no direct way of communicating as there is no guarantee that both will be running at the same time and they are separate processes.

    The OS does not provide an API for communication so the two prefered methods are...

    1. Use a web service to sync to data from Foreground App to Background Agent
    2. Use Isolated Storage to share data between the Foreground App and Background Agent

    In regards to credentials - there are methods available to encrypt the data in .NET, but for future reference, PasswordVault is available if you target WP8.1 (SL or XAML).