07-05-2011 01:48 PM
Hi,
I am trying to make a splash appear while my application make an http request. The application is not entering the invokeLater portion of the code. Here is my code:
final SplashScreen thisScreen = new SplashScreen();
Thread threadToRun = new Thread() {
public void run() {
// First, display this screen
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(thisSc reen);
System.out.println("-------the screen was just pushed");
}
});
// Now run the code that must be executed in the Background
try {
runThis.run();
System.out.println("------the thread is running");
} catch (Throwable t) {
t.printStackTrace();
throw new RuntimeException("Exception detected while waiting: " + t.toString());
}
// Now dismiss this screen
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(thisScr een);
System.out.println("-----the screen was just popped");
}
});
}
};
threadToRun.start();
in other words, the only thing running is runThis.run()
07-06-2011 04:57 AM
Hi,
i have written some code to display SPlash Screen. Hope this helps for you.
public SplashScreen(UiApplication ui,MainScreen next)
{
super(ScrollView.NO_VERTICAL_SCROLL);
this.application = ui;
this.next = next;
addManager();//layout of the screen
SplashScreenListener listener = new SplashScreenListener(this);
this.addKeyListener(listener);
timer.schedule(new CountDown(), 3000);
application.pushScreen(this);
}
public void dismiss()
{
timer.cancel();
application.popScreen(this);
application.pushScreen(next);
}
private class CountDown extends TimerTask
{
public void run()
{
DismissThread dThread = new DismissThread();
application.invokeLater(dThread);
}
}
private class DismissThread implements Runnable
{
public void run()
{
dismiss();
}
}
protected boolean navigationClick(int status, int time) {
dismiss();
return true;
}
protected boolean navigationUnclick(int status, int time) {
return false;
}
protected boolean navigationMovement(int dx, int dy, int status, int time) {
return false;
}
private class SplashScreenListener implements KeyListener
{
private SplashScreen screen;
public SplashScreenListener(SplashScreen splash)
{
screen = splash;
}
public boolean keyChar(char key, int status, int time)
{
boolean retval = false;
switch(key)
{
case Characters.CONTROL_MENU:
case Characters.ESCAPE:
screen.dismiss();
retval = true;
break;
}
return retval;
}
public boolean keyDown(int keycode, int time) {
return false;
}
public boolean keyRepeat(int keycode, int time) {
return false;
}
public boolean keyStatus(int keycode, int time) {
return false;
}
public boolean keyUp(int keycode, int time) {
return false;
}
}
07-06-2011 10:02 AM
I am trying to make an http request while the splashscreen is getting displayed, not just displaying a splash screen...it doesn't seem that this code will do the trick...any other suggestions?
07-07-2011 07:15 AM
do u want to show splace screen when ur background process is working?
07-07-2011 07:24 AM
try this code:
class SplashScreen extends MainScreen{
LabelField lb ;
public SplashScreen(){
BitmapField bf = new BitmapField(Bitmap.getBitmapResource("default.png"
add(bf);
Thread thData = new Thread(new Runnable(){
public void run()
{
UiApplication.getUiApplication().invokeLater (new Runnable() {
public void run()
{
try{
Advertisement ads = new Advertisement();
ads.PropertyTypeXML();
UiApplication.getUiApplication().pushScreen(new SearchScreen(ads));
}
else{
lb.setText("Error in Connection.");
}
} catch(Exception e){System.out.println("Error ==> " + e.getMessage());}
}
});
}
});
thData.start();
}
}