locked
How does the main app gets update from Share contract?

    Question

  • Consider I have my app running and also provide a share target. Operations that are done in the share contract should be reflected in the main app. 

    Currently I do not see any way to let the main app know that something was added to the apps DB. Are we supposed to poll the DB once the main app comes into the foreground again?

    Monday, June 25, 2012 9:22 AM

Answers

  • Hi Phil,

    In short your application is activated in two ways :-

    1) ActivationKind = Launch

    2) ActivationKind = ShareTarget

    So, in above Activation modes, your app will be in two different but independent states. You should be able to use the LocalSettings and the activated event to have a sync. I haven't tried it so far but seems like it should work. Reference  -- http://msdn.microsoft.com/en-us/library/windows/apps/hh465102.aspx

    -Sagar

    • Marked as answer by phil_ke Tuesday, June 26, 2012 12:36 PM
    Tuesday, June 26, 2012 12:29 PM
    Moderator

All replies

  • Hi Phil,

    I'm not quite sure I understand your scenario here, but it sounds like you're asking for interprocess communication between the share source and target outside of the actual contract. There is no supported way to do this.

    The share contract is one way: the share source provides the data and the target can extract and copy it, but cannot change the original data or communicate back to the source app (except to use a ShareOperation object to say when it is done).

    --Rob

    Monday, June 25, 2012 11:56 PM
    Owner
  • The scenario is that:

    1. I have my app running. It displays a bunch of items in a listview

    2. While this app is started, the user switches to another app and then opens the share Charm and selects my app as a share target.

    Now 2 instances of my app are running (well, one is in suspend mode, the first one). The one that was started as share target modifies the items that should be displayed in my app that was launched first. So when the share target is done with its work, how does my first app get to know about it? When the user switches back to my first app instance, should it just reload the items that are displayed in the listview (and were potentially modified by the share target app instance)?

    Tuesday, June 26, 2012 11:23 AM
  • Hi Phil,

    In short your application is activated in two ways :-

    1) ActivationKind = Launch

    2) ActivationKind = ShareTarget

    So, in above Activation modes, your app will be in two different but independent states. You should be able to use the LocalSettings and the activated event to have a sync. I haven't tried it so far but seems like it should work. Reference  -- http://msdn.microsoft.com/en-us/library/windows/apps/hh465102.aspx

    -Sagar

    • Marked as answer by phil_ke Tuesday, June 26, 2012 12:36 PM
    Tuesday, June 26, 2012 12:29 PM
    Moderator
  • Sagar that might, work.
    Tuesday, June 26, 2012 12:36 PM
  • So, do we have final answer for this question?

    phil - finally how did you implemented this functionality?

    Saturday, June 30, 2012 2:20 AM
  • I implemented the functionality using the "resume" event of the app. I then simply reload the database. The problem is: you cannot test suspend/resume while the debugger is attached. When you move away from the app and the debugger is attached it will not be suspended. But you can simulate suspend/resume from the debug toolbar.

    Another solution would be to have a file written to the temp location of the app and have the main app wait for changes in this file using the AQS file query object. I will implement such and will publish the drop-in code for that. The file could even contain informations about what to update or even plain simple JS code that could be executed by the main app then. 

    Monday, July 2, 2012 11:43 AM