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
rakesh86shankar
Posts: 1,003
Registered: ‎05-22-2009
My Device: Not Specified

Issue with object instance coming different for singleton class

Hi


I have singleton class getting initalised at the start of my app.I have thread class which which listens to send SMS in it and once i get SMS in my thread class ,I am trying to use instance of singleton class and save in it which has vector in it ,but my instance is coming as null for the thread for the first time but for the second time ,it show instance of first instance created during send first time.

For the other thread which receive SMS,instance is same as which as initialised during app launch,What is mistaking i am making which cause this issue.

 

Thanks

Rakesh

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

Re: Issue with object instance coming different for singleton class

I am confident you are attempting to use a static reference to your Singleton class.  In BB Java, a static instance is a Singleton within one Application COntext.  So this works if you don't run any code that runs as part of another application.  But you have listeners, and they will normally run in the context of the Application that you are listening too.  So they do NOT see your Application's static instance, they see their own and it will not have been initialised.

 

Fix using a Singleton in RuntimeStore:

http://supportforums.blackberry.com/t5/Java-Development/Create-a-singleton-using-the-RuntimeStore/ta...

Please use plain text.