There...
I created a new project with just the code I need (didn't want to bother you with all of the code)
So what would I need to do to push the screen (if it's not already displayed)
Whatever I try, I always end up with a illegalstate exception :(
Code:
class TestPushScreen extends net.rim.device.api.ui.UiApplication
{
public static void main(String[] args)
{
if(args != null && args.length > 0 && args[0].equals("gui"))
{
TestPushScreen instance = new TestPushScreen();
instance.enterEventDispatcher();
}
else
{
mBackgroundThread = new BackgroundThread();
if(mBackgroundThread == null)
{
//impossible to create thread... so exit
System.exit(-1);
}
else
{
try
{
Thread.sleep(2000);
mBackgroundThread.start();
}
catch(Throwable ie)
{
}
}
}
}
TestPushScreen()
{
mMainMenu = MainMenu.createMainMenuInstance();
pushScreen(mMainMenu);
}
public static MainMenu mMainMenu;
public static BackgroundThread mBackgroundThread;
Code:
/*
* MainMenu.java
*
* © <your company here>, 2003-2005
* Confidential and proprietary.
*/
/**
*
*/
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import javax.microedition.media.*;
import javax.microedition.io.*;
import java.io.*;
import javax.microedition.rms.*;
class MainMenu extends MainScreen
{
MainMenu()
{
mTest = new BasicEditField("Hello","");
add(mTest);
}
public static MainMenu createMainMenuInstance()
{
//Ensure this is a singleton instance.
try
{
//Open the RuntimeStore.
RuntimeStore store = RuntimeStore.getRuntimeStore();
//Obtain the reference of MainMenu.
Object obj = store.get(RTSID_MY_APP);
if (obj == null)
{
//Store a reference to this instance in the RuntimeStore.
store.put(RTSID_MY_APP, new MainMenu());
return (MainMenu)store.get(RTSID_MY_APP);
}
else
{
return (MainMenu)obj;
}
}
catch(ControlledAccessException e)
{
System.err.println(e.toString());
return null;
}
catch(Throwable e)
{
e.printStackTrace();
return null;
}
}
public static MainMenu getMainMenuInstance()
{
//Ensure this is a singleton instance.
try
{
//Open the RuntimeStore.
RuntimeStore store = RuntimeStore.getRuntimeStore();
//Obtain the reference of MainMenu.
Object obj = store.get(RTSID_MY_APP);
if (obj == null)
{
return null;
}
else
{
return (MainMenu)obj;
}
}
catch(ControlledAccessException e)
{
System.err.println(e.toString());
return null;
}
catch(Throwable e)
{
e.printStackTrace();
return null;
}
}
public static final long RTSID_MY_APP = 0x33abf322367f9019L;
BasicEditField mTest;
}
Code:
/*
* BackgroundThread.java
*
* © <your company here>, 2003-2005
* Confidential and proprietary.
*/
/**
*
*/
class BackgroundThread extends Thread
{
BackgroundThread()
{
}
public void run()
{
while(true)
{
try
{
//Code to push screen if not already pushed here
Thread.sleep(5000);
}
catch(Throwable ex)
{
}
}
}
}
Mmmm...
I was able to get the instance of my app and then call the pushScreen...
no error but the screen isn't displayed.
when the app tries to push it again after 5 seconds, I get a runtime error saying the screen is already pushed...
If it IS pushed, how come I don't seen it?
-- edit
I was able to display the screen.
I forgot to call "requestforeground"
Now, the problem is that after the screen is displayed, the thread stops running.
So it doesn't check for futur calls of pushscreen...
I want the thread to still run in the background, even if the screen is already displayed.
It WILL result into a runtime error, but I don't mind.. I just catch it and do nothing with it..
any ideas?