Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
ashishjmeshram
Posts: 154
Registered: 01-08-2010
My Carrier: Vodafone
Accepted Solution

How to prevent creating multiple instances of the application?

Hi

 

We have a UI Application. The application has been set to Auto run on Startup and as a System Module.

 

The application has a folder listener which checks for any new emails.

 

When we start the UI application by clicking on the app icon it seems that the multiple instance of the application is being created. Because of this when we send an email to the application it is receiving email multiple times. Sometimes single, twice and sometimes even five times.

 

 

 

public class MyApplication  extends UiApplication implements FolderListener,
		SystemListener, GlobalEventListener {




	// Boot
	public static void main(String[] args) {
		if (args != null && args.length > 0 && args[0].equals("gui")) {
			// code to initialize the app
			fromService = false;
			// register the notification
			Notification n = new Notification();
			n.registerNotificationObjects();

			Utilities.writeLog(GUID, "MyApplication GUI Starting up");
			MyApplication service = new MyApplication();
			service.enterEventDispatcher();
		} else {
			Utilities.writeLog(GUID, "OnBoardV2 Service Starting up");
			MyApplication service = new MyApplication();
			service.enterEventDispatcher();
		}
	}

	public void messagesAdded(FolderEvent e) {
        /// Receive messages  
        }   



}

 

 

 

 

Any help in this regard will be apreciated!

 

 

Thanks

 

Please use plain text.
Developer
ashishjmeshram
Posts: 154
Registered: 01-08-2010
My Carrier: Vodafone

Re: How to prevent creating multiple instances of the application?

[ Edited ]

Hi

 

I forgot to mention that we also implement SystemListener and application is also started on device start up. Could this be the reason ?

 

But then at times it responds only once to an email.

 

 

 

Please use plain text.
Developer
Developer
CMY
Posts: 961
Registered: 02-10-2009
My Carrier: Verizon

Re: How to prevent creating multiple instances of the application?

I dont know if that is your whole code, but if you register your app as a folder listener ever time it is invoked then you are registering multiple listeners. The listener does not get removed cause your app closes, you have to explicitly remove the listener. You need to either put the listener in its own class and only register on startup or find a way to chek if the listener is already registered every time the app is invoked.

Please use plain text.
Developer
ashishjmeshram
Posts: 154
Registered: 01-08-2010
My Carrier: Vodafone

Re: How to prevent creating multiple instances of the application?

Hi

We just found out that the application was being registered as a folder listener twice, once when the application starts on the device start up and once again on starting UI by clicking icon.

We have now removed the code to register application as a folder listener on UI startup.

We understand that this has resulted in application receiving email twice. But still we could not figure out how it was receiving emails 3, 4, 5 times?

Any clue on this?

Thanks

Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: How to prevent creating multiple instances of the application?

Each time someone exited and restarted the application a new listener was added?

 

If the problem has been resolved by your change I would almost guarantee that was the cause.

Please use plain text.
Developer
ashishjmeshram
Posts: 154
Registered: 01-08-2010
My Carrier: Vodafone

Re: How to prevent creating multiple instances of the application?

 

Yeah. It looks like the problem has been solved by that change.

 

Thanks for the help.

Please use plain text.