06-04-2012 08:20 PM
I'm in the planning stages of a rather ambitious app that will run on smartphones running 4.5-7.1
Depending on what's left of me after that effort, it may also go on the tablet.
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:
with and pass data0 as the integer representing the state .
In the UiApplication subclass this:
will get the event, analyze the state and determine the next screen to fire off.
When all info has been collected, the UiApplication subclass will run a Thread to communicate with a server and I'll rejoice.
Is this an appropriate use of global events?
Does invoking postGlobalEvent and sending it the process id of the UiApplication subclass guarantee that ONLY my UiApplication subclass will receive notification of that event? I've read the docs, but am still a little unsure.
06-05-2012 03:15 AM
06-05-2012 03:45 AM
I agree with the comments already made:
1) "Is this an appropriate use of global events?"
Not in my opinion.
2) "Does invoking postGlobalEvent and sending it the process id of the UiApplication subclass guarantee that ONLY my UiApplication subclass will receive notification of that event?"
No, all Applications will receive your notifications.
Simon has suggested a call back within your Application. In fact your UiApplication class is easy to find from any screen, UiApplication.getUiApplication(). will return an instance of your UiApplication. So you can easily use it as the hub for this processing anyway.
06-05-2012 08:26 AM
I can't help thinking that if I saw the same question in a non-blackberry java discussion then Mark's architecture would be considered a good design because it allows a very abstracted model. In the Blackberry world it seems to be considered good design to do things like those that have been suggested. Gosh it makes me shudder.
06-05-2012 08:32 AM
06-05-2012 09:02 AM
It probably was not a useful comment and let’s not get into a flame war over it, but the concept of asynchronous messaging is a tried and proven design pattern. As we try to achieve maximum abstraction and modularity, we generally do not want to directly connect components or objects, but rather we want to publish and subscribe or generally use a messaging paradigm, the BB apps use this as their model anyway. JME does force us to rethink these models as we try to achieve maximum efficiency, mainly due to limited hardware resources, but I do feel that the limitations in the Blackberry API especially in earlier releases have put Blackberry developers in a quite strange mind set.
Another example was when someone recommended to call an event handler directly for the purposes of avoiding the need to add permissions, that seems to be considered normal in the BB world but from a java design perspective, most commercial developers would get shot for doing such a thing in a commercial java application, because you're interfering in the event processing.
While this forum is not the place to learn java, it does concern me that less experienced java developers are going to learn some very bad habits by following some of the recommended designs.
06-05-2012 09:16 AM
06-05-2012 10:52 AM
The components can be sufficiently abstracted simply by using the Observer/Observed design pattern (IMHO).
Simon, I remember when J2ME was defined (late 90's, if I'm not mistaken) and I'm not quite 100 years old.
06-05-2012 11:03 AM
This has been very useful.
I've cooked up another design and posted it at http://supportforums.blackberry.com/t5/Java-Develo
Just to kinda provide some closure on this topic, here's why I scrapped the global events notification model.
Smartphones are constrained environments compared to desktops and other servers - smaller cpu, less memory yadda yadda yadda.
Consequently, I like my apps to not bother any other apps they don't have to. Using global events for my purposes is telling every app running on the device stuff that only my app is interested in. Overkill, IMO.