Hi. I am making an HttpConnection in my app and loading content into the application. Depending on the length of content this operation may take quite long on a regular phone and during this time the application seems as if it has stopped responding.
So, what I would like to do is display a message (TextBox or an Alert) informing the user that application is trying to connect.
I tried setting current displayable to Alert, and then calling the method making HttpConnection. At the end of the method, when connection has been made and data has been transferred, I am setting Displayable to a TextBox with the retrieved data.
However, the application skips the alert screen and goes directly to making HttpConnection and the TextBox.
So, my question is how can I display one screen until an operation is complete and then show another screen? Thank you for the input.
May be you can try make like this one for illustration we have 3 class
1. class Main
2. class result
3. class error
so at main you class you can try like this
// if that result is ok going to class result
// goes to class error
// close your connection
You're problem is that you're performing the networking in the UI thread. Since all the http methods are blocking methods, you're blocking the UI thread, and it's the UI thread that's in charge of changing screens. So it only gets around to changing the screen after the networking is finished, hence it skips the alert.
You'll have to spawn a new thread to perform the networking in.
Anytime you have some processing to do that may take a while (.5 seconds is also a while), you shouldn't do it on the UI thread (ie, in commandAction(), or keyPressed(), etc.).
Thanks a lot for your posts. I would prefer to keep my current class system and for this reason, I want to first experiments with threads.
I constantly get the notification (on emulator) that network connections are potentially blocking and that I should perform them through thread other than command action. Until now this hasn't been an issue on the real phone and I haven't bothered (shame on me).
My question then is "how?" - how do I spawn another thread to perform networking, if networking still needs to be performed upon user requesting info?