BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-07-2008, 09:42 PM   #1 (permalink)
New Member
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: rogers
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Repainting MainScreen - Thread

Please Login to Remove!

I am a very new arrival to the world of Blackberry JVM development and an amateur Java Hacker. I am attempting to write an application that uses Screen/MainScreen for layout of fields and other things, however I want to repaint or invalidate every 5 secs the Mainscreen using another Thread in the application. However using this Thread
Code:
class PrimeThread extends Thread {
         PrimeThread() 
         {
         }
         public void run() {
            try{
               
               HelloWorld hw = new HelloWorld((new Random()).nextInt());
                sleep(5000);
            }
            catch (InterruptedException e) {}
         }
     }
I want to pass a random number to the new instance of the APP, and I am using the following UiApplication methods in my HelloWorld class to try to repaint the screen

Code:
Application.getApplication().invokeLater(new Runnable() {
              public void run() {
UiApplication.getUiApplication().updateDisplay();
UiApplication.getUiApplication().pushScreen(HelloWorld);
}
But after compiling, the application Screen is just frozen, never updates , even though I know the thread is running. I also tried with UiApplication.getEventLock() but to no effect. It seems that the Mainscreen can only be painted once.... and refuses to be repainted, InvalidateAll, updateDisplay.... etc.
I am probably needing to have a Listener somewhere to get this to work ?? Any simple code sample or help would be greatly appreciated, (BTW I am learning Java still so please be gentle)
Offline  
Old 10-08-2008, 03:00 AM   #2 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

it seems that you push your screen to the screen stack again and again although it is already on it. The apllication itself is still running, so there will be no new instances created - not sure if you want it really...

either use callbacks in your thread or pass the whole screen to the constructor of your thread so it can be repainted ( with invalidate() ) or only the values of some fields.
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 10-08-2008, 05:56 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 8130
PIN: N/A
Carrier: US Cellular
Posts: 82
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you really need a separate thread? Why not use a recurring timer in your main thread?
Offline  
Old 10-08-2008, 07:34 AM   #4 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

you can modify your screen while it is displayed. use add/delete methods to add or remove fields and managers.
or push a new screen. the same screen can only be pushed once unless it is popped.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 10-09-2008, 02:58 AM   #5 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Give a look to Thread doesnt run !!!! HELP!!!
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.