Search code examples
blackberryblackberry-jde

SplashScreen On Blackberry


Hi I wanna add a SplashScreen to my Blackberry Application, i modified the code from here and modified it to this :

package main;
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 java.util.*;

public class SplashScreen extends MainScreen {
    private UiApplication application;
    private Timer timer = new Timer();
    private static final Bitmap _bitmap = Bitmap.getBitmapResource("SPlachS.png");
    public SplashScreen(UiApplication ui) {
        super(Field.USE_ALL_HEIGHT | Field.FIELD_LEFT);
        this.application = ui;
        this.add(new BitmapField(_bitmap));
        SplashScreenListener listener = new SplashScreenListener(this);
        this.addKeyListener(listener);
        timer.schedule(new CountDown(), 5000);
        application.pushScreen(this);
    }
    public void dismiss() {
        timer.cancel();
        application.popScreen(this);
        application.pushScreen(new MyScreen());
    }
.....


I just modified the constructor and that's all (i also tried the code from here) but I'm always having an Uncaught Runtime Exception


Solution

  • For splash screen simply use this in your constructor..

    Thread th = new Thread() 
            {
                public void run() 
                {
                    try 
                    { 
                        Thread.sleep(2000); 
                    } catch (Exception ex) 
                    { 
                    }
                    UiApplication.getUiApplication().invokeLater ( new Runnable() 
                        { 
                            public void run () 
                            {
                                UiApplication.getUiApplication().pushScreen(newScreen);
                                close();
                            }
                        }
                    );
                }
            };
            th.start();
    

    add everything to the screen before this thread.. I tried thid. hope it will work for u..