08-11-2010 11:39 AM
Good day all,
I am currently in the process of writing an application to monitor the output of certain services on our company server.
I'm rather new to writing apps for blackberrys so I need alittle help with a problem.
My code works, but when I run the app on the phone it locks out all user input. I believe this is because my code is never returning to the main method, because my code loops infinately inside a class function.
/* do check of Server Services via HTTP Connection*/
What is the proper method of running my check every 30 seconds without locking out the device? I only need help with the looping, the rest of my code works.
Any help would be greatly appeciated.
08-11-2010 11:48 AM
... or create a Timer, wrap your code in a TimerTask and schedule it to run every 30000 ms. Effectively you are also using another Thread, but you don't call those sleep()s yourself...
08-11-2010 12:02 PM
this is not correct @arkadyz, timer should not be used to execute blocking operations.
a separate thread is the correct approach, you can use a while(true) look or use a boolean to be able to cancel it.
notice that a poll every 30s will kill the battery very fast.
i would strongly suggest to use a push technique. on bes devices BES-push (very easy), on others BIS-push (quite new) or a trigger email. your device would then poll the server for the announced update, no need to send big data in the trigger message.
leverage the strengths of blackberry, push is one of them.
08-11-2010 12:17 PM
Thanks, I'm really surprised at how fast I got replies.
I'll look into running on a different thread. Can you provide a good example of running code on a different thread or point me in the direction of a good tutorial?