Trying to update a "Loading" label... "while you wait for a thread

Hello, I am new to Java and BlackBerry, so it is a double learning curve for me.  I tried searching for an answer and we have tried a number of things, but I do always get the label that I update to display.  Any help would be greatly appreciated.  I have a main screen with a label field.  I start a thread, and that this thread works I loop and try to update the label as in the httpdemo example.  I do this in refreshMenuItem.  The code looks like she change the label, but the screen does not appear to refresh and show the update label.  Any advice?  Thank you.

public class testLoadingMainScreen extends MainScreen
{

   private boolean isLoading;
   private LabelField statuslabel;

   public testLoadingMainScreen()
   {

      LabelField title = new LabelField("Loading Demo", LabelField.USE_ALL_WIDTH);
      setTitle(title);

      statuslabel = new LabelField("Waiting...", LabelField.USE_ALL_WIDTH);
      add(statuslabel);
   }

   Public void requestSucceeded(final String message)
   {
      isLoading = false;
      updateContent(message);
   }

   public void requestFailed(final String message)
   {
      isLoading = false;
      updateContent(message);
   }

   private MenuItem _refreshMenuItem = new MenuItem("Refresh List" , 10, 10)
   {
      public void run() {

         //setup the status messages.
         String[] statusMsg = new String[6];
         StringBuffer status = new StringBuffer("Loading");
         statusMsg[0] = status.toString();
         for ( int j = 1; j < 6; ++j)
         {
            statusMsg[j] = status.append(" .").toString();
         }

         updateContent("Starting...");

         isLoading = true;

         //start the thread
         try
         {
              testLoadingThread dispatcher = new testLoadingThread(testLoadingMainScreen.this);
              dispatcher.start();
         }
         catch (Exception e)
         {
              System.out.println(e.toString());
         }

         //while thread is working, update status message
         int i = 0;
         while ( isLoading )
         {
            updateContent(statusMsg[++i%6]);
            try
            {
               Thread.sleep(500); // Wait for a bit.
            }
            catch (InterruptedException e)
            {
               System.err.println(e.toString());
            }
         }

      }
   };

   protected void makeMenu(Menu menu, int instance)
   {
      menu.add(_refreshMenuItem);
      menu.addSeparator();
      super.makeMenu(menu, instance);
   }

   private void updateContent(final String text)
   { 

      //synchronized(UiApplication.getEventLock()) {
      //    testLoadingMainScreen.this.statuslabel.setText(text);
      //    testLoadingMainScreen.this.invalidate();
      //}

      UiApplication.getUiApplication().invokeLater (new Runnable() {
         public void run()
         {
            testLoadingMainScreen.this.statuslabel.setText(text);
            testLoadingMainScreen.this.invalidate();
         }
      });
   }

}//end testUImainscreen class

public class testLoadingThread extends Thread {

    testLoadingMainScreen screen;

    public testLoadingThread(testLoadingMainScreen screen) {
        this.screen = screen;
        }

    public void run() {

        //put thread to sleep so I can test informative labels
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
            screen.requestFailed(e.toString());
        }

        screen.requestSucceeded("Sucess");

    }//end run

}//end testLoadingThread class

MenuItems run in the UI thread... don't sleep() in them.  I guess that's causing your problem of update to block the UI thread.  Use rather a reason for recall with a background thread making sleep if you need regular notifications to the user interface.

~ NN

Edit: On coffee/reflection, recall patterns may be overkill here... you can simply use a Timer/TimerTask.

Tags: BlackBerry Developers

Similar Questions

  • While you wait for spare camera for 40 days. My k910 has speaker failure. : ()

    What a piece of crap... My k910 start failure involved while I'm waiting for spare camera... Call speaker is ok, but the media here totally dead speaker... It's my problemfull phone I've ever had... My past a706 and my wife s920 are problemless...

    Fortunately after a tried to push both the up and down button of the active again speaker volume...

  • ORA-00060: Deadlock detected while you wait resource

    Hello

    I have a trigger to an underlying table. It fires after that insertion of the events in the underlying table. When I try to update some columns in a table underlying even within the trigger, I get the error below.

    ORA-00060: Deadlock detected while you wait resource

    Can anyone clear or correct me.

    Thank you

    Ignore the Aurélie. It is just a spammer who is trying to promote some criminal website.

    A deadlock occurred if two different sessions lock resources. Each session can wait the other session ends.

    I suppose that you set up a trigger and use the 'autonomous transaction' wrongly to a commit. This function creates a new session. Now you have two (or more) session that could create deadlock. Committing inside a trigger from the table is ALWAYS bad (with some exceptions).

    Solution: remove the pragma of your relaxation. Then the other problems you get with it.

  • I HAV been trying to update my expiration date of credit card for 3 months.  When I go to lelien for "Update payment Details" and edit the expiration date and &lt; click &gt; save, I get an error saying my address in invalid.  I have several chat sessions

    Can someone please help...  Suggestions, how can I overcome this problem, in which case my Adobe Creative cloud subscription will expire today due to and credit card.

    I tried to update my expiration date of credit card for 3 months.  When I go to the "Update payment Details" link and change the expiry date then < click > save, I get an error saying my invalid address.  I had several chat sessions with support, called support and logged a ticket with support and every time they tell me to go to a particular link to update my contact information.  I do and I get the same error...   "My coordinates are not valid."  Now I'm in the position where my creative cloud membership will expire today everything simply because the Adobe address validation do not think that my address is valid.

    I got 'Cat' sessions with the support,

    I made a phone call to the support and

    I logged a ticket with support.  I'm really trying to pay my subscription.  Support ticket No. 0216009991

    Whenever I have contact the support they gave me a link to the site where I supposedly can I enter my credit card details.

    Whenever I went on the link provided, I'd get the same error.  "My coordinates are not valid."

    What I checked on my address.

    1. I look out the window and the view I get is the same as it was yesterday and the day, and in fact several years ago.

    2. I go out in the street, Yes, the street sign says the name of my street

    3. I go to my mailbox and it does not say the number of my mailing address

    4. yes I get the email to the address registered with Adobe

    5. yes I received the email from adobe delivered to the address

    6. I get the address of Google, yes I can find it on Google

    7. I converted to use the satellite view Google maps

    8. Yes, it's my house, with the 12 solar panels on the roof

    9. Yes, that's my black car in the driveway

    10. I check my reviews for my address Board rate, Yes, this is the address that I recorded with Adobe

    11. Yes, I had this same address registered at Adobe for the past 3 years.  So far I have not had a problem with my address

    12. I work with a software company that actually uses the address of Google, under license validation, built-in in their application.  I used this software to check to see if my address is recognized as valid.  You guessed it is recognized as valid.

    I did check my credit card

    12. Yes, I have, every time checked the status of my credit card with the Bank

    a. the card is valid

    b. the card's not over it's credit limit

    c. the card is not due

    d. the address registered to my credit card with the Bank is the same address that I recorded with Adobe

    Since the last link Adobe support gave me two weeks ago, to change my credit card details, I was able to key a new credit card in the fields (Yes it's good that I was forced to get a new credit card only for Adobe!   If I am that everything would be fine.

    But wait...   The details I provided this link have not been updated on the Adobe site.  (So I check the link... I was scammed to get my card number?)

    After investigation of the link, I'm fairly confident of the link provided is a true link to Adobe.  www.adobe.com/go/Secure

    Did anyone else had this type of problem when you try to update the expiration date of a credit card?

    The question is about to have an impact on my ability to process pictures for my photography business, it affects my ability to earn an income.

    So you could say I'm getting angry some of the stuffing!

    In summary...  I knew that my credit card had a new expiration date and I tried to update the expiration 3 months 3 months.

    Simply because the use of the validation of addresses, Adobe, has a few flaws, I was not able to update this information.  So Adobe today will stop my subscription.

    As I said in previous support tickets, chat sessions and telephone.  I'll be more disappointed if I am prevented from using software and Adobe cloud features.

    It is copied from an email I received during the night from Adobe...

    Continue to create with us

    Hi Thomas,

    Your Creative cloud membership will expire on August 23, 2015 (PT). We hope that you have been getting the best out of all that creative cloud has to offer. To extend your subscription, please update the billing for your account information, or add a prepaid card.

    Update your billing information (there is a link to where I can update the expiry date) pocztek sigh...   I still get the same error telling me that my address is not valid!

    Thank you for being a part of the creative cloud,

    The creative team Cloud

    Good creative team...  I REALLY WANT TO STAY IN THE TEAM, AS YOU CAN SEE FROM THE FOREGOING, THAT I REALLY TRIED TO SOLVE THIS PROBLEM SEVERAL TIMES OVER THE PAST 3 MONTHS.

    I tried to include as much information as possible in what I said earlier, I expressed in a way that will hopefully provide a little humor, but at the same time to portray the frustration I'm feeling right now.

    Honestly, I don't know what more I can do.  It seems that I have no other recourse start litigation for loss of income coming from Adobe address Validation errors.  There is a real chance that I will be litigated against because I won't be able to complete contracts.

    There must be a healthier solution of mind that court proceedings.

    Kind regards

    Thomas Croll

    (Tom)

    Tom, let me some time. I I will get these verified case and will contact you.

  • ORA-00060: Deadlock detected while you wait the cursor CLOSE resource

    Hello

    I am a new Member of this forum. I work with a problem that we have obtained a few weeks ago. It runs in the lot C Pro executable on 10 threads dealing with > 800 data accessed from more than one table. The error, such as reported was a package.function call.

    This is the error I encountered:
    process_item ~ G *, D * ~-60 ~ ORA-00060: Deadlock detected while you wait resources ~ PACKAGE ERROR = cursor CLOSE C_ * in the R package *. I * 7641

    The slider is a simple SELECT without Table or record locking.

    My questions are:
    * During the occurrence of this error, execution is already in the line of the CLOSE cursor or did the error has occurred between the OPEN and the CLOSE slider? There are several lines of code between the OPENING and CLOSING:
    -one who calls to a package.function that simply stores the values of parameter to a variable
    -another one that retrieves the cursor. The group that contains the values of the cursor is used only by a single function in the package

    * Is it possible for this CLOSE cursor cause a deadlock? What could have caused this?

    * From what I know, Oracle treats blocks by abandoning the blocking process, while others continue, but this impasse caused our program to hang. How is that possible? The origin of the impasse might be our Threading program? This is a rare event and has past that twice this year.

    Thank you
    RAF

    RAF Serrano wrote:
    I see, so it be that blocking has occurred before the CLOSE cursor or it occurred during CLOSING? The cause could be executable ProC

    first cause is NOT ProC

    or is it really an error in PL/SQL

    first cause is NOT PL/SQL.

    cause of ORA-00060 is DML (INSERT, UPDATE, or DELETE)

  • How long should you wait for your apple account unlock

    How long should you wait for your apple account unlock?

    of > If your identifier Apple is locked - Apple supports

    ...

    When you see one of these alerts, you can go to iforgot.apple.com to unlock your account with your existing password or reset your password. After multiple unsuccessful attempts to unlock your account, your identifier Apple will remain locked and you can try again the next day.

    ...

  • When is it OK for looping while you wait event?

    Newbie question: in a world of logic non-blocking, when is it a good idea to loop waiting for something finish?

    For example, I am told to check to END_OF_MEDIA (via PlayerListener) to see if a song I played with ToneControl is finished. So is it possible to just create a loop and wait for it be triggered?

    Here is a very simple (albeit artificial) example. I want to play a melody (using ToneControl) twice. I play once, wait until it's done, then play again. END_OF_MEDIA tells me it's done. But have I not need to sit in a loop, then waiting for END_OF_MEDIA? Is it OK? It looks bad, but I don't know what would be the 'right' way.

    Thank you.

    Roricka

    The code I used was something called an anonymous inner class Java. Here's another version that does not use this construction somewhat obscure:

    void startTune() {    Player p = Manager.createPlayer(...);    p.addPlayerListener( new MyPlayerListener() );    p.start();}
    
    class MyPlayerListener implements PlayerListener {    public void playerUpdate(Player player, String event, Object eventData) {        if (event == END_OF_MEDIA) {            processEndOfMedia();        }    }}
    

    Note This class myplayerlistener is declared inside the MyScreen, right as well as the methods of the class and variable fields. All this has done is to convert an anonymous inner class in an inner class with a name.

    Now, it might look like you can move then comes from the MyPlayerListener class in a separate file named MyPlayerListener.java. But this does not work, at least not directly. The reason is related to one of the strange features of inner classes in Java (anonymous or not): an instance of an inner class carries with it an implicit reference to an instance of the containing class. That's why playerUpdate() can call processEndOfMedia() as if it was a MyPlayerListener member function, even if it is a member of MyScreen function. Somehow, an instance of MyPlayerListener lives a dual identity as an instance of MyScreen.

    If you want that myplayerlistener has stated in its own file (or if you want her to be a top-level class, not public in MyScreen.java or a static inner class of MyScreen), the rules of the language to say that there can be more than double-identity of nature. At this time, you cannot call the processEndOfMedia() in the same way as a MyPlayerListener instance does not have a reference to an instance of MyScreen. (In fact, it has no way of knowing that processEndOfMedia() is a function in the class MyScreen!) The way out of this is to give MyPlayerListener a way to refer to a particular instance of MyScreen. Here's one way:

    class MyPlayerListener implements PlayerListener {    private MyScreen client;    public MyPlayerListener(MyScreen client) {        this.client = client;    }    public void playerUpdate(Player player, String event, Object eventData) {        if (event == END_OF_MEDIA) {            client.processEndOfMedia();        }    }}
    

    Then, back in MyScreen, you need to change the call to the constructor:

        p.addPlayerListener( new MyPlayerListener(this) );
    

    And if you put MyPlayerListener in another package that MyScreen, you must also change the visibility of public processEndOfMedia().

    Anonymous inner classes are very convenient for these listener classes little, but they do not have the code a bit difficult to read. Put them in their own compilation units are more work, but it makes the code a little easier to manage, especially when come back you after a few months and try to understand what made you the way back when.

  • QML pauses while you wait thread.

    I have a connection that the screen when you press the "CONNECT" button, I want the buttons disappear and to display a progress bar.

    My code when you press LOGIN:

    Set the visible property of the button to false and progress bar to true visibility.

    Create a thread and connect to my web service and get the answer.

    Wait thread ends with pthread_join()

    Handle the response and either make visible the new button or go to another part of the application.

    The problem is the button do not disappear or the progress bar appears. They only AFTER the pthread_join().

    Any suggestions on what I can do to fix this? I just want to prevent the user from spamming the "connect" button while he checks the connection information.

    Thank you!

    Updates to the user interface will not happen because you have blocked the UI with pthread_join() thread.

    I did something very similar to the HelloCamera example:

    https://github.com/BlackBerry/Cascades-community-samples/tree/master/HelloCamera

    When the user presses the button "Take a picture", I grey out and start my threads of work (hidden inside the camera_take_photo() implementation).   When one of my sons indicates completion, I emit a SIGNAL which is intercepted by a SLOT function in my application that makes the visible button again.

    I suggest that your button handler marks itself invisible or disabled, creates a thread and not to join this thread.

    Instead, when that thread terminates, it should send a SIGNAL.  While your application has a SLOT Manager related to this signal, which makes the visible button again and joins in your thread.

    In short... SIGNALS and SLOTS is your solution.

    See you soon,.

    Sean

  • I'm trying to update Java 8U45 in Firefox 39.0 for windows 8.1. The udpdate did not finish. I get an error 1603. What should I do?

    I have Firefox 39.0. The next generation Java plug-in 11.45.2 for Mozilla browsers shows that it is vulnerable. When I try to update my plugin on Firefox for the Java 8 51 version update, it downloads and try to install it, but will not complete the installation. I get the error message 1603. I try to use the online version of 32-bit.

    Try to uninstall Java and download and install Java 8u51 full offline Setup.

    You can find the last 32 bit Java versions on the Oracle's Web site.

    See the Platform Java > Java SE 8u51 (download of JRE; 32-bit for Windows)

  • on the version 24 tried to update to 25 says install in waiting and will not update.

    Apparently on 10/11/13 at 01:31:34 firefox made an update of version 24 25 version security. At that time, my system may have done a backup on a USB key. By checking other problems on my system that has to do with hesitation video I looked at the version of firefox. When I go to the help section says I'm on version 24. When I click on the look of updates, it says that a newer version is available. I click to download, and it fails. No error message. When I go to the troubleshooting information page and look at the history of the update. It is said that the 25 version has been installed and is pending installation. How can I get the new version? I could save a lot of bookmarks and afraid to just install the new version. Any ideas on what I can do? Appreciate the help.

    rich Oros

    Please ignore. System reboot update firefox latest version. My bad...

  • When I start my laptop Vista loaded, I get 'Please Wait' for more than 2 minutes sometimes. What does Vista behind my back?

    I have a Toshiba laptop with no extra or odd options, this is the case whenever I start and it's annoying when Vista was announced as being quick to start.  This small circular thing continues his tail for up to 4 minutes while the 'Please Wait' shines.  Very unsatisfactory.  I also bought the best virus/malware protection money can buy, at least that's what they say, it's a bit like microsoft.

    Check if the same problem occurs if you "clean boot" your system (check this page). This should load Windows Vista without third-party programs. If the startup time is better, then you will need to find or which program is causing the problem.
    However, you can check this page first.

  • While loop, wait for the function and the stop button!

    Hello

    I have a while loop and a stop button. Inside my While loop - I have a 'Wait (x ms)' function. If I press the stop button, it does not block the program immediately, he expects ms x then stops the program. How can I get rid of this?

    Thanks in advance for the help!


  • You have locked my thread about the problems you answer!

    Hi you have locked my thread about the difficulty you answer on certain subjects, but you still have not solved the problem. This makes it very difficult and frustrating when trying to help a member. If you would leave my thread open, I might just be able to guide you to the problem.

    PS: If there's a better place to post these things, please advise and I will comply.

    Dokie!

    http://h30434.www3.HP.com/T5/desktop-operating-systems-software-recovery/Hi-trouble-replying/m-p/344...

    This problem is only on certain topics. Can be difficult to fix?

    Are you sure that someone takes care of this problem?

    The forum is having serious problems Dokie! It is "wanted" to what I read - but still give problems tonight. The sections of the laptop are also heavy attacked by porn spammers. I have to wonder if they are which is the root of some of the problems that we see.

  • How long should you wait after badly answering security questions too many times in a row

    How long should you wait after badly answering security questions too many times in a row

    How long should you wait for what? If you have temporarily disabled your account screen should say how long you have to wait until you can try again. If you mean for the reset link show on your account then does not appear if you have an e-mail address of verified relief on your account, if you have not you don't you must follow the section "If you can not reset your security questions" at the bottom of the page you have posted since

  • "Error R6034: an application has made an attempt to load the library runtime C incorrectly." while trying to update iTunes. Tried to reinstall, but get error "Windows error 1114.

    Original title: Runtime Error R6034

    When I was updating my Itunes library, I got a pop window with this message:

    Runtime error
    Program of C:\ Program files (x 86) \itunes exe.
    R6034
    An application has made an attempt to load the C runtime incorrectly library.
    Please contact the team for more information application support
    I tried to repair itunes without success and then uninstalled itunes and tried to reinstall it but when I tried to reinstall I get a different error message (error Windows 1114)
    Can you help me?

    Hello

    This seems to be a new issue facing users of iTunes while trying to update to the latest version of iTunes on Windows 7. I checked in the Apple support sites and found that uninstalling iTunes and then put it back in place, by running the installer with administrator privileges has solved the problem for many users with similar problems.

    You can see the responses made by user turingtest2 in the following threads of the Apple Support forums, the steps are correctly described here:

    https://discussions.Apple.com/message/24609674#24609674

    https://discussions.Apple.com/message/24616175#24616175

    The steps which have been voted as useful for these discussions include:

    First, uninstall each of these programs from your computer:

    • iTunes
    • Apple Software Update
    • Apple Mobile Device Support
    • Hello
    • Apple Application Support

    Then, Download and save the installer for iTunes by clicking on this link: http://www.apple.com/itunes/download/

    And finally, reinstall iTunes by running the installer registered with elevated permissions. Here's how you can do this:

    1. Right click on the installer downloaded.
    2. Click run as administrator.
    3. Click Yes or continue when Windows ask you for your consent.

    This should help you solve this problem. If you are still not able to get the iTunes program works correctly, you can also post your request in the iTunes of Apple Support Forums. Here is the link for forums:

    https://discussions.Apple.com/community/iTunes/itunes_for_windows

    Let us know how it goes. We will be pleased to be of further assistance. Thank you and have a nice day!

Maybe you are looking for

  • White screen on Toshiba virtual store - account 33090

    Hello I have created a personal account Toshiba today and after updating the app, I get white screen. Help, please... Personal account is 33090Thank you.

  • Phoenix 860-170VR: adding additonal hard drive

    I would add additonal hard drive to my PC and I see there are locations for additional disks, but looks like I need rails to mount the disk, so it can slide into the slot. HP sells these rails and if yes, someone has a link or a reference number? Tha

  • Satellite A200 - 14 d PSAECE - Fn keys not working not not & other function keys

    Hello (1) I ask your help on installing my Fn keys drivers for my laptop Satellite A200 14 D PSAECE.My OS is Windows XP and I have Bitdefender Internet Security 2009.Drivers Toshiba download page, I got all the drivers for my laptop (36 of all - or c

  • My Macbook Pro reboots after a memory leak every two hours

    Hey everybody. I'm having a problem with my MacBook Pro (retina, mid-2012), where he is recovering in market (usually after gel). In this case only (so far) while using Adobe Illustrator CC 2015 (to date). I also use a Wacom tablet (intuos 4, with la

  • How to read the CBS. Open a session?

    The last 2 days I get a message when windows live messenger tries to start up ' is either not designed to run on windows or it contains an error. " "Install new or contact the software provider ', I tried a system restore, but the problem still persi