08-15-2008 11:34 AM - edited 08-15-2008 11:41 AM
My application has a background thread doing stuff and when the user opens the GUI (2 entry points), it needs to display the current state of the thread. I've been looking at the following:
http://www.blackberry.com/knowledgecenterpublic/li
but there are a few things that I don't understand.
(1) What is the following long value?
public static final long RTSID_MY_APP = 0x7451402f595f81a5L;
(2) Is this even a good example for what I'm doing?
I only need to obtain a state from the thread (int).
08-15-2008 11:47 AM
08-15-2008 11:56 AM
How does one generate a RTSID then?
Actually the GUI already has a reference to the thread. However, since I only do the following when the GUI is closed, the GUI is actually still running. Anyway, how can I get the thread to continuously update the textField when the GUI is active?
public void close(){ Application.getApplication().requestBackground(); //hides screen }// close
08-15-2008 12:05 PM
Just to prove if you get two developers you will get two different ways of doing it, I would put the background thread into RuntimeStore with a GUID known by the UiApplication. When the UiApplication starts, it can find the background thread, and call any method it likes on it (e.g. getStatus()). Note that you should also use isAlive() on the Thread first to make sure it is actually still running!
08-15-2008 12:19 PM - edited 08-15-2008 12:33 PM
That will only work once because I only set it to background on close. The GUI cannot be restarted!
The GUI already has a reference to the thread, I just need to continuously update the state!
I think I can solve it by having the thread take a reference of the GUI...
08-16-2008 01:43 PM
Ok, I tried having the background thread take a reference to the GUI, but it won't work because there are 2 entry points - either 2 instances of threads will be created (the code below), or the GUI is not linked to the thread (when I move new bgThread and bgThread.start() to within the else statement.
Please help !!
final class Sync extends UiApplication{ private static long imsiLong; private static MyGUI myGUI; private static BackgroundThread bgThread; // 2 entry points, defined in 2 projects public static void main(String[]args){ imsiLong=findIMSI(); myGUI=new MyGUI(imsiLong); bgThread=new BackgroundThread(myGUI); bgThread.start(); // Load the GUI (entry point 1) if(args!=null&&args.length>0&&args[0].equals("gui"
)){ new Sync().enterEventDispatcher(); }// GUI else{ // Blackberry Autostart (entry point 2) }// autostart }//main
08-18-2008 04:25 AM
08-18-2008 07:40 AM
08-18-2008 08:25 AM
08-18-2008 08:33 AM - edited 08-18-2008 11:29 AM
Yeah, but I wanted the background thread to update the GUI so it takes an instance of the GUI. The background thread has to be created before the if statement for the GUI, or the link will not be established (if the thread is created/started in the else statement)
Edit: Fixed! Basically, RuntimeStore is used to check if an instance of background thread exists.
else{ //autostart bgThread=BackgroundThread.waitForSingleton(); bgThread.start(); }// autostart public static BackgroundThread waitForSingleton(){ RuntimeStore rtStore=RuntimeStore.getRuntimeStore(); Object obj=rtStore.get(RTSID); if(obj==null){ rtStore.put(RTSID,new BackgroundThread()); return (BackgroundThread) rtStore.get(RTSID); }// if not created else{ //already created return (BackgroundThread) obj; }//else }// waitForSingleton