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
Contributor
liptaka
Posts: 24
Registered: ‎09-19-2011
My Device: 9900
My Carrier: Vodafone Hungary
Accepted Solution

Thread.sleep() - no effect

Hello,

 

I would like to ask for your suggestion for the follwing problem.

I have a midlet using LWUIT for BB 9900 with OS7.1.

Inside the midlet I try to use the following:

- after startup, display a "loader" page with loader animation, and during the midlet is doing some actions

- right after  I display another page (secondForm)

 

My problem is that the foirst laoder page disappears very fast...almost it can not be seen at all.

 

What I did is the following:

 

private delay del;

Thread delayThread = new Thread(del);

...

...

loaderform.show();

delayThread.start();

..

..

private class delay implements Runnable {

public void run()

   try{  

    Thread.sleep(3000)

}catch (InterruptedException e)

{}

   secondForm.show();

    

}

}

 

 

The result is not ok. It seems the Sleep() does not work at all. There is no any delay, immediately I get

the second form appearing.

 

Do anybody have some idea what can be the problem?

 

Thanks in advance for any comments,

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Please use plain text.
Developer
maadani
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Thread.sleep() - no effect

Hi,

 

Your delay thread actually sleeps but it does not affect the UI thread.

 

You don't need to put any thread to sleep.

 

First, display your form with the animation:

loaderform.show();

 

Then, inside your loader form schedule a timer task to run after X seconds (check docs for Timer & TimerTask).

 

Your timer task would run after X seconds and will show the second form:

secondForm.show();

 

Hope that helps,

 

E.

Please use plain text.
Developer
Hithredin
Posts: 401
Registered: ‎06-03-2010
My Device: Z10 Red
My Carrier: Free

Re: Thread.sleep() - no effect

Even easier, use this:

 

UiApplication.getUiApplication().invokeLater( yourRunnable, 3000);

Please use plain text.
Developer
Eugen
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE
My Carrier: Vodafone NL

Re: Thread.sleep() - no effect

Just my five cents.

 

I would try to avoid splash screens if you really can achive it.

 

Because of user perception 

Please use plain text.
Developer
tklanilkumar
Posts: 206
Registered: ‎02-22-2011
My Device: BB TORCH & 9800
My Carrier: idea

Re: Thread.sleep() - no effect

Hi liptaka, I want to use LWUIT for MIDLETS nd you mentioned that you used that tool. So can you suggest me can I use this tool in eclipse other than netbeans.
*****************************************************************************
* Give kudos when you like it
* Mark it as a solution if it fixes your issue
Please use plain text.
Contributor
liptaka
Posts: 24
Registered: ‎09-19-2011
My Device: 9900
My Carrier: Vodafone Hungary

Re: Thread.sleep() - no effect

Hello tklanilkumar,

 

I also started to work in eclipse, but I was not successful with LWUIT. Simply somehow I was not able to make the blackberryport.jar included into the final .cod file. It is a generic problem of any external jars as far as I know.

I have read several posts on this topic, but finally I could not make it work.

So rather I started to use netbeans instead.

It is not so nice, after compilation I have to use the blackberry tools (rapc, jarsigner, etc), but it works.

 

br,

Please use plain text.
Contributor
liptaka
Posts: 24
Registered: ‎09-19-2011
My Device: 9900
My Carrier: Vodafone Hungary

Re: Thread.sleep() - no effect

Hello maadani,

 

i have tried what you suggested, but it seems does not work (result is the same, no any delay..):

 

 

inside my initForm() method of loaderform:

...

...

this.show();

timer = new Timer();
timertask = new MyTimerTask();
timer.schedule(timertask, 3000);

}

...

....

 

private class MyTimerTask extends TimerTask{ 
   public void run()
         {  
                            secondform.show();
         }
   
    }

 

 

I really do not understand why it doe snot work. The secondform.show() should be called only after the delay....however it is displayed immediately :-(

 

 

 

Please use plain text.
Contributor
liptaka
Posts: 24
Registered: ‎09-19-2011
My Device: 9900
My Carrier: Vodafone Hungary

Re: Thread.sleep() - no effect

This method works!!! Thank you very much!!
Please use plain text.