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
Developer
KeniF
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

enterEventDispatcher() concept

Hi, I have 2 entry points for my application, GUI and the background thread. 

I'm not sure whether I should have both of them enterEventDispatcher().

 

In this example,

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800783/How_To_...

 

only the GUI is made to enterEventDispatcher() but the background thread isn't.

 

However, in here

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800783/How_To_...

 

There is no user interface but the background thread is made to enterEventDispatcher().

 

Why? What does "event dispatching" mean?

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: enterEventDispatcher() concept

information from javadoc

 

public void enterEventDispatcher()
Enters the event dispatcher.

The thread that calls this method (typically the main thread in the application) becomes the event-dispatching thread, which will execute all drawing and event-handling code.

Note that under normal circumstances this method does not return.

 

Developer
KeniF
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: enterEventDispatcher() concept

[ Edited ]

So, what exactly is event handling? Is implementing listeners event handling?

 

Also, can we enter the dispatcher more than once:

 

GUI extends UiApplication and

BackgroundThread extends Application

 

Is it good practice to have a UiApplication AND an Application?

Message Edited by KeniF on 12-21-2008 06:21 PM
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: enterEventDispatcher() concept

[ Edited ]

Event handling is processing of incoming events.

 

You press keys, navigate trackball, roll trackwheel - all of them are events and they are sending to the application that entered to event dispatcher.

 

As it is said in javadoc 

 

Note that under normal circumstances this method does not return.

 

How do you plan to invoke enterEventDispatcher() twice ?

 

You can make two applications and interact with each other via GlobalEvents.

 

Perhaps the following link will be useful for you:

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800783/How_To_...

 

Message Edited by tbilisoft on 21-12-2008 06:25 PM
Developer
KeniF
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: enterEventDispatcher() concept

[ Edited ]

We can enter event dispatcher twice because of alternate entry points - The background process is automatically started, enters event dispatcher. And when the user clicks on the icon, the GUI part of the main thread is run, enters event dispatcher again (?)

 

In the example you quoted, the event handling thread FolderListenerApp never really entered event dispatcher.Why?

Message Edited by KeniF on 12-21-2008 07:09 PM
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: enterEventDispatcher() concept

Yes, you're right. Listener part does not invoke enterEventDispatcher()

 

 

//Get the store from the default instance. Store store = Session.getDefaultInstance().getStore(); //Add the folder listener to the store. store.addFolderListener(this);

 

It just registers the necessary listener with Store instance.

 

And when a folder event occured this listener is notified and the relevant method is invoked.

 

As you can see there is no need to enter event dispatcher twice.

 

Only GUI Application enters event dispatcher.

 

Developer
KeniF
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: enterEventDispatcher() concept

However, BB treats 2 entry points as separate processes. The GUI won't work if only the Background thread enters event dispatcher and vice versa.

 

Can anyone confirm this?

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: enterEventDispatcher() concept

What do you mean by "doesn't work"?  What problem are you having?  Note that an application can move itself into the foreground or background by calling Application.requestForground or Application.requestBackground.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
KeniF
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: enterEventDispatcher() concept

I guess I didn't explain it clearly, sorry.

 

In my main class, "gui" argument will launch a UiApplication, and without the argument, it will launch an Application (background thread). Am I doing this right? (2 applications and 2 enterEventDispatcher() ?) 

 

(I need to update the screen in the GUI and add listeners to the background thread) 

 

 

 

final class S{ // 2 entry points, defined in 2 projects public static void main(String[]args){ // Load the GUI (entry point 1) if(args!=null&&args.length>0&&args[0].equals("gui")){ new Gui().enterEventDispatcher(); }// GUI else{ // Blackberry Autostart (entry point 2) BackgroundThread.waitForSingleton().enterEventDispatcher(); }// autostart }//main }//S

 

 

 

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: enterEventDispatcher() concept

From what you have posted above, it sounds like you are on the right track.  If you get stuck at any specific point please post an update.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker