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
hitesh171285
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl
Accepted Solution

sendListener(sms) and folder listner invalk multiple times

i implement net.rim.blackberry.api.mail.event.FolderListener and net.rim.blackberry.api.sms.SendListener

 

toghether in my application

 

its work fine on simmulater

 

but when i test on device both called multitimes in that

 

i start both listner in aftre app start with internet

 

device 8520 os5.0 with wifi and EDGE

 

please any help for that how can i fix so its called once?

Please use plain text.
Developer
simon_hain
Posts: 15,939
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: sendListener(sms) and folder listner invalk multiple times

where do you register the listener? in an autostart part or on every startup?
do you de-register the listeners when you exit your app?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Regular Contributor
hitesh171285
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl

Re: sendListener(sms) and folder listner invalk multiple times

hey simon thanks for replay

app start on auto start and background app
i register listner in application startup for that i also implement SystemListener

and i dont deregister listner anywhere...!

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: sendListener(sms) and folder listener invoked multiple times

It does sound like your listeners are being started mulitple times as Simon said. 

 

Listeners like this are removed automatically by the system only on a cold restart, so if you want to make sure you only do this once, then that is the place to register the listeners.

 

Alternatively, I would save a flag in RuntimeStore.  Then you can check this flag to see if you need to register your listener.  RuntimeStore is cleared on a battery out reset.  Then you can do it at application start-up.

Please use plain text.
Regular Contributor
hitesh171285
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl

Re: sendListener(sms) and folder listener invoked multiple times

sorry for late replay ...!

 

my app formay

 

class NewTestApp extends Application implements SystemListener 
{
	public static void main(String [] args) 
	{
		NewTestApp appInstance = new NewTestApp();
		if (ApplicationManager.getApplicationManager().inStartup()) 
			appInstance.addSystemListener(appInstance);
		else 
			appInstance.doStartupWorkLater();
		appInstance.enterEventDispatcher();
	}
	private void doStartupWorkLater() 
	{
		invokeLater(new Runnable() 
		{
			public void run() 
			{
				doStartupWork();
			}
		});
	}
	private void doStartupWork() 
	{
		new Thread(new Runnable() 
		{
			public void run() 
			{
				try 
				{
					Application appInstance = Application.getApplication();
					//....
					//assign listner
					//....
				} 
				catch (Exception e) 
					System.out.println("==========error===="+e);
			}
		}).start();		
	}
	public void powerUp()
	{
		removeSystemListener(this);
		doStartupWork();
		}
	public void batteryGood(){}
	public void batteryLow() {}
	public void batteryStatusChange(int arg0){}
	public void powerOff() {}
}

 now in that things is possible multiple assign listner??

and when i cold reset blackberry do startup work run again?

Please use plain text.
Developer
simon_hain
Posts: 15,939
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: sendListener(sms) and folder listener invoked multiple times

powerUp is called after a "soft restart", which does not remove any listeners. this means you add them again.

your doStartupWorkLater also looks strange, please check if you changed the code from whereever you took it.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: sendListener(sms) and folder listener invoked multiple times

This logic will run every time you application is started.

 

If you are trying to set up listeners to run only once, then you normally set up an alternate entry point, and have the same code that you have below, in there.  Here is a KB article regarding an alternate entry point:

http://supportforums.blackberry.com/t5/Java-Development/Set-up-an-alternate-entry-point-for-an-appli...

 

Do you need your listeners running al the time, or only when your your user starts your application?

Please use plain text.