Reputation: 25
I am creating my very first blackberry application that tries to connect to a rest web service. I tried the example I found in the internet. Please refer to this link: http://mobile-development.org/index.php/blackberry/how-to-call-restful-web-services-in-blackberry
I tried to implement it in my simple BlackBerry application which is the one that is automatically created when you create a new BlackBerry project in BlackBerry Plug-in for Eclipse IDE. I just placed the code (literally copied and pasted it) in my button, that when clicked, will execute such code. But, when I click the button, the application hangs.
When I implement a code that simply outputs "Hello" in the output log, the application works perfectly fine. What is the reason behind it? Do I need to run the web service call in a separate thread? Please help. Thank you in advance.
--------------------PLEASE READ BELOW----------------------
I noticed that my application hangs because it waits for a response from the web service call of at least 2 min. I read through this: http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is_-_Different_ways_to_make_an_HTTP_or_socket_connection.html?nodeid=826935&vernum=0 -- and added "deviceside=true" at the end of the url (http://yourwebserviceurl.com;deviceside=true"). It works fine now. Maybe the proper implementation for this is to do the task in background or in a separate thread and set the timeout which I do not have a knowledge on it yet. I'm still confused on whether to set the deviceside to true/false. Should I set the deviceside to true when I'm running my app in a simulator then just change it to false if I want it to run in an actual device? That is for me to discover for now or you can help me out on this one as well. ;-)
Upvotes: 1
Views: 432
Reputation: 512
The Code they have given is in for HTTP connection , It is totaly fine, But what we need to do call this code in a thread , because ui works also in thread by which by which it got stuck. So you need to use thread concept here. Look at Samples provided into
Eclipse helios\plugins\<sdk version>\components\samples\com\rim\samples\device\httpdemo
Whenever you wants to update UI In a background thread , use
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
<Update UI>
}
});
I hope it may help you .
Upvotes: 1