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

Posts: 43
Registered: ‎11-24-2011
My Device: Perl
My Carrier: BB

How to refresh the current screen


I developed a code for the screen where on that constructor I use the :-

ReadXML() methos where I reade the xml.

DrawScreen() method where I draw vertical field manager and other fieldManagers for the desgine and finally a metho

add(vfMain);  which add the vertical field manager.



I want to write a code which will refresh the page & I write a function which I call at end of the constructor here is code:-


public void Refresh_page()
            Timer tt=new Timer();
            TimerTask task=new TimerTask() {
                public void run() {
                    // TODO Auto-generated method stub
                    vPerson = null;
                    vInformation = null;
                    vStartTime= null;
                    vCompanyName= null;
                    vId= null;
                    vMeetingType= null;
                    vPerson = new Vector();
                    vInformation = new Vector();
                    vStartTime= new Vector();
                    vCompanyName= new Vector();
                    vId= new Vector();
                    vMeetingType= new Vector();
                        invalidateAll(0, 0, width, height);
            tt.schedule(task , 2000);
        catch(Exception e)
            SOP("Timer Errorr "+e);

This code goes to refresh the screen on every two second

and when I compile it on debugg mode I will goes for the fail at  delete(vfMain);


need help for this problem.....



Posts: 16,894
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to refresh the current screen

a timer task is not a separate thread.
blocking operations, like downloading and parsing xml, should be done in a separate thread.

you delete vfMain, but you do not add it again, so your second run will try to delete a field that is not part of the screen.
looking at the detail message of the exception should tell you things like that.
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to refresh the current screen

Agree with Simon and would like to add a couple of points:


I think invalidate() does not do what you think it does.  It repaints existing Fields - that is all.  When you add and delete Fields from the Screen, the screen knows that it will be updated and repaints itself.  So your invalidate()s are actually just causing overhead.


What you are doing is effectively polling.  In most circumstances a better solution is to have a listener.  In other words, have something that is told that data on the screen has been updated, and it controls the redisplay, not some timer loop that is blindly updating the screen every 2 seconds regardless of whether data has changed or not. 


On final thing. Adding and deleting Fields plays havoc with scrolling and focus.  If you have more than 1 screen of data (which you might have on a small device even if it fits fine on a Torch 9810) and/or the users can scroll round these Fields, what you are doing will probably give a bad user experience.