Updade UI thread

Hello

I want to show a list of message on a scree. I have to get a web service messages, showing a popUpScreen with a message waiting, while the service is invocated.

To do that I have created a RespuestaServicio interface and three classes, MyScreen where I want to display messages, it implements RespuestaServicio methods that are called after the Web service response is obtained, PleaseWaitPopupScreen extends from PopupScreen, which has a method that receives a thread to run while the popupscreen is showed and close itself when the thread end and finally

LlamadaWSThread is passed to the PleaseWaitPopupScreen call and that the webservice to get the list of messages.

It's code summarized:

public class MyScreen extends MainScreen implements RespuestaServicio{

    private VerticalFieldManager listaMensajes;

    public MyScreen() {
        super(Manager.NO_VERTICAL_SCROLL);
        HorizonlatFieldManager fondo = new HorizonlatFieldManager();
        listaMensajes = new VerticalFieldManager();
        vertical.add(listaMensajes);
        fondo.add(vertical);
        this.add(fondo);
        buscarMensajes();
    }

    public void buscarMensajes(){
    // Here I get some parameters like url an xml to pass to LlamadaWSThread constructor
       LlamadaWSThread serviceCaller = new LlamadaWSThread(url, this, xml);
              PleaseWaitPopupScreen.showScreenAndWait(serviceCaller);
    }

    private void llenarLista(String[] campos){
        LabelField campo;
        for(int i = 0; i < campos.length; i++){
            campo = new LabelField(campos[i]);
            campo.setMargin(0, 10, 0, 10);
            listaMensajes.add(campo);
        }
    }

    public void requestFailed(final String message) {
       UiApplication.getUiApplication().invokeLater(new Runnable() {
                 public void run() {
                Dialog.alert("requestFailed: "+message);
                 }
              });
    }

    public void requestSucceeded(Document result) {
        String[] mensajes;
        // Here I proccess result to get mesajes...;
        llenarLista(campos);
    }
}
public class PleaseWaitPopupScreen extends PopupScreen {

    private static LabelField _ourLabelField = null;

    private PleaseWaitPopupScreen() {
        super(new VerticalFieldManager());
        ourLabelField = new LabelField("Please wait");
        this.add(urLabelField);
    }

    public static void showScreenAndWait(final Runnable runThis) {
        final PleaseWaitPopupScreen thisScreen = new PleaseWaitPopupScreen(text);
        Thread threadToRun = new Thread() {
            public void run() {

                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        UiApplication.getUiApplication().pushScreen(thisScreen);
                    }
                });

                try {
                    runThis.run();
                } catch (Exception t) {

                }

                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        if(thisScreen != null){
                            try {
               UiApplication.getUiApplication().popScreen(thisScreen);
            } catch (Exception e) {
               Dialog.alert(e.getMessage());
                  }
                        }
                    }
                });
            }
        };
        threadToRun.start();
    }
}
public class LlamadaWSThread extends Thread {
    private RespuestaServicio pantalla;
    private ConstructorXml xml;
    private String url;

    public LlamadaWSThread(String url, RespuestaServicio pantalla, ConstructorXml xml) {
        super();
        this.url = url;
        this.pantalla = pantalla;
        this.xml = xml;
    }

    public  void    run()
    {
        HttpConnection  conn = null;
        OutputStream    oStream = null;
        try
        {
            conn    =   (HttpConnection)Connector.open( url );
            conn.setRequestMethod( HttpConnection.POST );
            oStream =   conn.openOutputStream();
            oStream.write( xml.getXml().getBytes() );
            oStream.flush();

                  InputStream is = conn.openInputStream();
            byte [] response = IOUtilities.streamToBytes(is);
            is.close();
            ByteArrayOutputStream   baos  =  new ByteArrayOutputStream();
            baos.write( response );
            DocumentBuilderFactory  dbf =   DocumentBuilderFactory.newInstance();
            DocumentBuilder db  =   dbf.newDocumentBuilder();
            Document    doc =   db.parse( new ByteArrayInputStream( baos.toByteArray() ) );
            pantalla.requestSucceeded(doc);
        }
        catch (Exception except)
        {
            pantalla.requestFailed(except.toString());
        }
    }   

}

My problem is that I'm getting this exception:

IllegalStateExeption: UI engine accesed without hoding the lock of the event

When you call llenarLista (...)  of requestSucceeded (...) who is called to LlamadaWSThread

Please reread what I proposed. You missed a part on the displacement of campo in the body of the loop for?

What you see, it's quite normal - plan you a change in the user interface that will update the display with the contents of an object, once you're done. Then you quickly change the contents of this object before all your regular screen updates has a chance to be executed. No wonder that all of these updates are only the last value of this object.

Compare your loop for:

for (int i = 0; i < campos.length; ++i) {
  final String campo = campos[i];
  UiApplication.getUiApplication().invokeLater(new Runnable() {
    public void run() {
      listaMensajes.add(new LabelField(campo));
    }
  });
}

You see the difference?

Tags: BlackBerry Developers

Similar Questions

  • Thread of messages with false contacts

    I have a thread of messages which, since the installation of Sierra is showing the wrong contact and the mix of messages from the two contacts.

    It seems that this is because the two contacts work for the same company and have identical entries their: 'work' of phone field. If I remove the scope one of the contacts and Messages to restart, the thread returns to two threads separated by the correct contact.

    The two contacts have iPhones and different MOBILE numbers that show as being related to separate Apple ID I assume that before I upgraded, Contacts, or Messages has been able to use this information to treat them as separate persons. Also, I assume that's the way it should work.

    How do I get things to normal?

    Thank you very much

    Christian

    Hello

    Change/edit the name of the field map to read 1 or something that prevents the binding.

    Report it here http://www.apple.com/feedback/ (there is no one of the separated Contacts).

    22:00 Friday. September 30, 2016

     iMac 2.5 Ghz i5 2011 (El Capitan)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro (Snow Leopard 10.6.8) 2 GB
     Mac OS X (10.6.8).
     iPhone and iPad (2)

  • Deleting an old thread

    A mod can please remove the following thread? Or, at the very least, delete the official names in the upper part and the response after the second answer?

    I deleted the e-mail program and he want to come back.

    In addition to many years old and useless, I don't want the display name associated with the post. The account associated with this post is no longer active and has been under a now defunct e-mail address, so it is impossible for me to connect you and redact my credentials or remove the post.

    Thanks for any help you can provide. It would be greatly appreciated.

    I reported to our guests, now it is them. Even if you had access to the account, you would not be able to edit or delete the post, you have 15 minutes to change.

  • Thread of mail IOS10

    I prefer how IOS9 mail works, no Adviser how to select a thread without developing all the emails to the right?

    I have HHHAAATTTE the way watch mail thread ios10. ios9 was so much more functional and effective!

  • iOS 10 Mail app - threads are impossible to read with style answer-everything Outlook (without quotes)

    Outlook and the Mail app both old showed you a list of e-mails in a thread; If you want to dive to an email, you must click on this email.

    The new view of thread is essentially impossible to use now, since there is no view that shows each email in a list. Instead, if reply - all on your e-mail service does not add to citing it vertically and mark a horizontal line between the contextual emails, you end up seeing the WHOLE thread in each individual e-mail. It's 100% fine if you also have a vision where you can see every email truncated in a list. But this is no longer the case.

    I'm going to have to cut the wires completely from my computer (Outlook) is impossible for me to read in the current state.

    100% behind you! Please Apple, can we have an option to make the threads as they were in the iOS 9? It was actually a useful feature. In iOS 10, it is completely impossible / a lot of your time!

    Even if the quirks have been developed and e-mails would collapse correctly it is always not very useful when you have long filaments (which, when you use mail app for email to work can happen in the course of a single day with 20-30 + emails).

  • View threads AND grouped by date/conversation

    Hello

    I try to have messages see the thunderbird grouped by date (with a thread on today, yesterday, last week, etc.) and within these threads, see email conversations. A conversation that began three weeks ago, but has received a new email today is expected to manifest itself in the thread today, but from the first email of the conversation.
    I did not understand if it is possible, as grouped by (Date) and Threads are mutually exclusive. Any ideas?

    Thank you

    As you say, it is there only one group so at the time. So I guess that your out of luck.

    You could fill a better bug report and see if one of the developers interested. https://Bugzilla.Mozilla.org/

  • Do not thread conversations

    no thread.

    just separate emails from the same topic scattered everywhere.

    I just restored by mozbackup.

    What gives?

    Paradive said

    no thread.

    just separate emails from the same topic scattered everywhere.

    I just restored by mozbackup.

    What gives?

    solved.

    UN/re-installing Conversations ended.

  • After the update 42, partial load in memory (Task Manager), but the software antivirus keeps thread bound to perform but only loads 2nd &amp; subsequent.

    Manager tasks shows Firefox loaded as a service, but a of threads waiting to complete. There is no application shown in the Task Manager (which seems reasonable that Firefox has not loaded).
    There is no error message. The 'circle of rotation of microsoft"is going for a few seconds, then disappears as if the schedule.
    It happens after 2nd & subsequent charges after reboot. Firefox seems to work the first time after reboot. It happened only after upgrade to 42. Clean installation makes no difference. Chrome works OK
    Worked well up until the 42 update. Tried to do a clean install with the box to inform Mozilla erased.
    Maybe Firefox started using a port that is blocked by the antivirus? I don't get no logging for the virus scanner showing what it to be blocked. A comprehensive analysis reveals nothing.
    Operating system is Windows 10 (64-bit)

    Abandoned trying to actually find what is actually happening. Changed software virus scanner.
    I think (and this is just a guess) is that to integrate with windows update update 42 change the output method to the telemetry file the antivirus does not. It is perhaps that the antivirus cannot manage that file or property, but it does not record the fact, a failure of the antivirus.
    There is a hint of doubt in my mind when an upgrade causes a system that works to fail in a non traceable method.

  • 'Threading' has started on my incoming emails; How can I remove it?

    I want to see all my emails separately - not 'threaded' together in the subject line. I don't have a clue as to why - after years of use - thread just started a few days ago?

    Sort by view by Unthreaded

  • Please tell us how to remove the 'message thread function' in the column 'Object' of my Inbox.

    Hello!
    For some reason, the column of the object on the Inbox of my e-mail account now has the topics of conversation. I have no idea how the son got there - and you would appreciate the help in eliminating these threads.
    Thanks a lot for your help.

    In the main menu bar:
    View (Alt - V) - sort by - Unthreaded

  • If you ask the question and then choose a solution, the thread will be closed or still can you ask more details?

    If you ask the question and then choose a solution, the thread will be closed or still can you ask more details?
    (sometimes, someone answers my question, and I want to mark it as the solution and am not yet quite ready for the thread be closed...)

    If you still experience this issue, you can return to this thread.
    But, you must clear the flag solved .

  • In the messages application, what is the blue circle on the right side of certain threads?


    After thinking about this topic, I discovered that the blue circle means that the recipient of a thread is a contact. Thanks anyway.

  • When I delete a message that is part of a thread, how can Thunderbird 38.0 I delete a single message?

    In the new 38.0 Thunderbird, I can't simply delete a message if I was sending and receiving messages back & forth with someone using the button answer. When I click to delete a message, it tells me that all messages in the thread will be deleted and my only options are to cancel or delete them all. How can I remove just a message from a thread?

    Thank you!

    If you have your e-mails showing that "thread", you will get the issue you discuss.

    So remove the threading and then delete the specific emails.
    You can do this by clicking on the column header icon 'display messages '. It is usually the first column heading.

    or select "no":
    'View' > ' sort by ' > 'unthreaded.

  • I want to display send them and received messages in a thread

    Messages are threaded but send messages on the same topic do not appear in the threaded list.

    https://addons.Mozilla.org/en-us/Thunderbird/addon/Gmail-conversation-view/?src=SS

    This add-on may be

  • Prefer to get new threads to a new e-mail message in the Inbox

    My Inbox now displays an old Email previously sent with wires to listed. However, I don't see a new thread as a new separate Email as before, but only as a nother wire. He is easy to ignore these new messages. I'd rather get a new message, even if it's a wire, appear in my Inbox as a new message

    View (alt + V) menu > sort by > non threaded

Maybe you are looking for