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
Highlighted
Regular Contributor
Posts: 83
Registered: ‎05-24-2011
My Device: Storm 9550
My Carrier: XXX

code not threading properly with splashscreen

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(thisScreen);
                        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(thisScreen);
                        System.out.println("-----the screen was just popped");
                    }
                });
            }
        };
        threadToRun.start();

 

in other words, the only thing running is runThis.run()

Regular Contributor
Posts: 53
Registered: ‎06-29-2011
My Device: Blackberry 9800
My Carrier: o2

Re: code not threading properly with splashscreen

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

 

BR,
Supriya
Regular Contributor
Posts: 83
Registered: ‎05-24-2011
My Device: Storm 9550
My Carrier: XXX

Re: code not threading properly with splashscreen

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?

Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: code not threading properly with splashscreen

do u want to show splace screen when ur background process is working?

Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: code not threading properly with splashscreen

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