01-15-2010 03:41 AM - last edited on 01-15-2010 03:41 AM
Hello,
I have been recently reading more about RuntimeStore and Singleton and how it is "best practice" not to create a static instance of Ui/Application.
I have coded myself up a storm where I reference the Ui/Application in the
public static void main(String [] a){} so I need for the application instance to be static.
Because I have coded with this critical mistake (although I have managed to keep some complicated code bits together) I am thiking I should root out this problem before I go any further.
The main reason I use an instance of Ui/Application in the main method is due to the fact that I check for RuntimeStore instances and if my application instance does exist, I need a "container" Ui/Application static instance to receive the Singleton.
How would I go about uprooting my issue? I will try to parse out some of my code later.
Thank you for your help!
01-15-2010 07:24 AM
I'm not sure I understand why RuntimeStore does not provide you with an easy answer to this question.
Currently I presume you do something like:
MyAPP....
to reference things that are 'static' in your application, i.e. shared stuff that you can access from anywhere.
I suspect that you can just replace all of these with
MyAPP.getInstance().....
Where getInstance obtains the singleton entry in RunTimeStore that has the data you want. I think this KB article explains this:
How to - Create a singleton using the RuntimeStore
Article Number: DB-00686
http://www.blackberry.com/knowledgecenterpublic/li
01-18-2010 12:41 AM - last edited on 01-18-2010 01:26 AM
I am all backed up and about to attempt some refactoring. The reason that my application instance is static is because I refer to the instance in auto start modules while in the static main method.
This in turn is because, in my auto startup module I make a singleton of MyAppInstance and then refer again to this instance in the "launch" module entry point for the static main method.
Thank you for your guidance!