Sections

How to develop ABC enabled applications

Resuming and suspending an activity rely on the ability to access state information for running applications. We call such applications stateful. In the present framework we differentiate between three types of stateful applications:

  1. Legacy applications with no programming API,
  2. Legacy application with an API, and
  3. Applications with full access to the source code.

In the first type of applications, only the name of the application, the window size, position, and executable are stored as state information -– this is the information that we can extract directly from the OS. When such an application is migrated in an activity from one device to another, the application window is restored but not the content or inner state. For any legacy application with an API, special-purpose application wrappers can be created. Internet Explorer, for example, provides a COM interface which is used to get access to the currently displayed URL and the scroll location on the page. This now allows application inner state to be restored when an activity roam.


// C#
[StatefulField(current-url)]
public URL CurrentURL;
[StatefulField(current-position)]
public int CurrentPosition;

Listing 1. - State annotations in a C# browser application.

The StatefulApplication interface in our C# programming model is used to develop stateful applications. To help implement state management in the application, fields that represent 'state' information can be annotated as stateful. The code-listing above shows an example of state annotations for an internet browser which ensures that the URL and the scroll position is saved as state information for this service. Stateful applications and their annotated fields are managed automatically by the framework and burdens the application programmer very little. Requiring the programmer to denote stateful fields in his or her program is a small overhead and even negligible compared to other requirements which an operating systems imposes on applications.

Example

An example of a simple application which have been activity-enabled is a standard chat application. The point of showing this application is to show how a simple application is easiliy activity-enabled - we do not hypthesize that a larger and more complicated application is equally trivial.

The basic idea in the chat-application is that a shared textbox will be used to display the text entered by any/all of the particpants. A second textbox is used to write the text-messages and the state of this textbox is used to communicate who are currently writing a message. This is accomplished by having two stateful UI-components.


Fig. 1. - The user-interface of the chat application. The numbers indicate which UI fields are state-enabled.

A RichTextBox (as seen in the figure above as (1)) which is simply annotated and has the system-defined default behavior. This means that the RTF content of the field is made part of the state of the application with the id talk_all.

A TextBox (as seen in the figure above as (2) ) which have a application-defined behavior. The code for the behavior is implemented in the overridden functions. This means that if the user is writing a message the value of the state-component with id talk_you will be '<user> is writing a message'. This value is set as the text of a status-field at marker (3) which means that all participants will be able to see who are currently writing a message.

Fields

The following is the public fields of the application, the only thing which has been added are the annotations, which now enable state to be shared, and the set- and getState methods which override the default behaviour of the talk_you field.


// C#
public class ABCChat : ABCApplication {
        [StatefulComponent("talkyou")]
        public System.Windows.Forms.TextBox tbTalkYou;
        [StatefulComponent("talkall")]
        public System.Windows.Forms.RichTextBox rtbTalkAll;

        public System.Windows.Forms.Button bTalk;

        private System.Security.Principal.WindowsIdentity user =
        System.Security.Principal.WindowsIdentity.GetCurrent();

        ...

        public override string getStateComponent(string id) {
                // write status string
                if(id.Equals("talkyou")) {
                        if(this.tbTalkYou.Text!="") return user.Name+"|writing";
                        else return user.Name+"|not_writing";
                }
                else return base.getStateComponent (id);
        }

        public override void setStateComponent(string id, string val) {
                if(id.Equals("talkyou")) setStatus(val);
                else base.setStateComponent (id, val);
        }

        ...

}

Listing 2. - The interesting parts of the Chat-applications source code.