08-25-2012 12:33 PM
i want to create background listener which will fire request to server after every 10 second and if update available then will alert to the user. how can i do that ?? please any tutorial or code sample.
08-25-2012 01:46 PM
I will suggest go with push (from server) instead of pull (requesting server for every 10 sec).
If you want to go with pull than use TimerTask and Thread to do this
08-25-2012 05:57 PM
As kamal_nigam suggests, using a push service, that sends updated data to the BlackBerry when it changes, is usually more efficient - because the BlackBerry only has to do work when there is updated data!.
For information on the PUSH service, see here:
This service is very efficient in terms of overhead - it is especially efficient in terms of Blackberry battery life - but of course does also minmise the data traffic which might save users a load of money too. The only downside of this is that it requires you to implement the push service as part of a web site somewhere. So you will need to have Server side programming skills involved in the team that develops this.
To use this the push service, from the BlackBerry coding perspective, you need a background listener, but the code samples provided will help you with this.
If you wish to create a pull service, you need to start a background process in the BlackBerry. This article might help with this:
However most people want to have a background 'listener' and have foreground User Interface. So they want something that will automatically start up when the BlackBerry starts up, and also have an application icon. The usual way to do this is to have an alternate entry point - so one entry point starts when the phone starts (your background listener), the other is started by the user clicking on the icon (the User Interface). This is described here:
I think you might also find this useful
Finally a little detail about your Background 'listener'. The first point to make is that doing this every 10 seconds will be a significant drain on the battery of the phone. Do you really need to do it that often?
And the second point in terms of coding, I personally would not use a Timer and TimerTask. I would just use a Thread. It is actually simpler using a single Thread and more efficient for the BlackBerry. The Thread would simply send the request to the Server, process the response (if any - you might get an errors), then wait for 10 seconds and do it again.
Hope this answers your questions. Good luck.
08-26-2012 03:28 AM
Hey Peter thanks a lot. i will refere the link which you have suggest me. and
" The first point to make is that doing this every 10 seconds will be a significant drain on the battery of the phone. Do you really need to do it that often?"
no i dont want to do that but for temprory i have to do pull request but finally i will go to push notification. and can suggest good blackberry book?? or website where i can find good tutorial .
08-26-2012 06:10 AM
".... for temprory i have to do pull request "
OK, then temporarily I suggest you have a delay that you can vary so that it is easy for you to test the effect of your polling time on the battery.
Regarding the best place to look for documentation on the PUSH API, the link I gave you is the best that I am aware of. I do not believe the API is documented in any books, certainly not in any of the books I have read.
Regarding tutorials, you can Google as well as I can, but there seem to be a few useful sites around including: