Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
juszczec2
Posts: 59
Registered: ‎05-10-2012
My Device: 8800

non global event design, was "global events usage questions"

I plan to have a multitude of screens collecting information from the user.  Then I'll run a Thread to start communicating this info back and forth to a server.

 

I'd like to use global events to communicate between the class that extends UiApplication and the screens.  The UiApplication subclass will kind of serve as a state machine.  Each screen will invoke:

 

postGlobalEvent(int processId, long guid, int data0, int data1, Object object0, Object object1)

 

Hi folks

 

This is another design in response to the feedback I got in http://supportforums.blackberry.com/t5/Java-Development/global-events-usage-questions/td-p/1748631

 

Here's a summation of the pieces parts of my app:

 

Multi screen app designed to collect a variety of info from the user.  After all info entered, start a Thread to communicate all info to a server and display any server responses to the user.

 

My basic idea is a UiApplication subclass acting as a state machine to coordinate/manage the creation/display of the different screens, accept their data, possibly scrub it and start the server communication thread.

In the linked thread, I was advised to use callbacks - so I've done some redesign and would like to solicit comments again.

My UiApplication subclass now passes a reference to itself to each of the screens.

 

My UiApplication subclass now has a method called:

 

 

public void processStates(Vector v){

switch (getState()){
  case STATE_1:
    -- display SCREEN1 --
    break;
  case STATE_2:
    -- display SCREEN2 --
    break; 
  case STATE_3:
    -- display SCREEN3 --
    break;
   case STATE_4:

     ServerCommunicationThread t = new ServerCommunicationThread(this, v);
     t.start();
     break; 
}

}

 

After the user enters all the info and presses a button to indicate they are done, the handler attached to the button does something like:

 

UiApplication.getUiApplication().invokeLater(new Runnable() {
  public void run() {
     -- create, load Vector v with data entered on this screen --
     <ref to UiApplication subclass>.setState(STATE_2);
     <ref to UiApplication subclass>.processWindowStates(v);
  }
});

 

and the process repeats itself until we've collected all the info and fired up the ServerCommunicationThread

 

The big advantage I see to this, as oppsed to my previous design using global events, is I'm not bothering any other apps with info that's only of any real concern to my app.  

 

Mark