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
Trusted Contributor
trupti
Posts: 242
Registered: ‎03-16-2010
My Device: 9530
Accepted Solution

Problem opening Splash Screen

[ Edited ]

 

Hello,

 

  In my BB application, I want to first show a splash screen and then go to normal screen. For that, in my main Uiapplication, I am calling :

public class MyAppStarts extends UiApplication {

        public MyAppStarts() {
                pushScreen(new SpalshScreen());
        }
         public static void main(String[] args) {
                MyAppStartsapp = new MyAppStarts();
                app.enterEventDispatcher();
        }

}

 

This is my SplashScreen inspired (taken) from http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800256/...

 version 4.2 and later

 

public class SplashScreen extends FullScreen {
        private Timer timer = new Timer();
        private Bitmap bitmap;
        private UiApplication app;
       
        public SplashScreen() {
                super(Field.USE_ALL_HEIGHT | Field.FIELD_HCENTER);
                System.out.println("******************** Into SplashScreen");
                try {
                    bitmap  = Bitmap.getBitmapResource("flash.png");
                } catch(Exception e) {
                    System.out.println("********* Exception : " + e.getMessage());
                    e.printStackTrace();
                }
                //this.app = ui;
                this.add(new BitmapField(bitmap));
                SplashScreenListener listener = new SplashScreenListener(this);
                this.addKeyListener(listener);
                timer.schedule(new CountDown(), 5000);
                System.out.println("Showing splash .....");
                UiApplication.getUiApplication().pushScreen(this);
        }
       
        public void dismiss() {
                timer.cancel();
                UiApplication.getUiApplication().popScreen(this);
                UiApplication.getUiApplication().pushScreen(new LoginScreen());
        }
       
        // class CountDown
        private class CountDown extends TimerTask {
                public void run() {
                        DismissThread thread = new DismissThread();
                        UiApplication.getUiApplication().invokeLater(thread);
                }
        }
       
        // class DismissThread
        private class DismissThread implements Runnable {
                public void run() {
                        dismiss();
                }
        }

        // class SplashScreenListener
        public static class SplashScreenListener implements KeyListener {
            private SplashScreen screen;
            public boolean keyChar(char key, int status, int time) {
               //intercept the ESC and MENU key - exit the splash screen
               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;
            }
            public SplashScreenListener(SplashScreen splash) {
               screen = splash;
            }
         }

    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;
    }
      
}

 

It throws, IllegalStateException - can't figure out where. I tried adding breakpoint at main class's pushScreen(new SplashScreen());, yet it throws the exception and couldn't know where is the exception causing. If I replace the SplashScreen with LoginScreen, it works perfectly. So their is something wrong with SplashScreen only.

 

Can anyone help mw know where am I going wrong or what more to do !

 

Any help is highly appreciative.

 

Thanks

 

 


--------------------------------------------------------------------------------
For any helpful answers give kudo's (star) to the helper.
Please use plain text.
GCR
New Contributor
GCR
Posts: 2
Registered: ‎10-08-2010
My Device: Not Specified

Re: Problem opening Splash Screen

First thing I can see is that you are invoking push screen twice, once in each constructor.

 

G

Please use plain text.
Trusted Contributor
trupti
Posts: 242
Registered: ‎03-16-2010
My Device: 9530

Re: Problem opening Splash Screen

Oh Thanks for pointing out that mistake.

After correcting that mistake also it didn't work at all. Finally I cleared applications from Download folder (could also just delete my those cirrent applications) and tried again and things were working perfectly.

 

I guess the main problem was also that the same application was already in Download folder and was executing again from JDE, and just application in cache would be running instead of newly added/updated one.

 

Just to see the results with invoking pushScreen again n SpashScreen constructor - resutls were still working properly only. Didn't throw any error/exception or showed screen twice or longer - just worked as expected. Hmm strange.

 

Any ways thanks.


--------------------------------------------------------------------------------
For any helpful answers give kudo's (star) to the helper.
Please use plain text.