Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 59
Registered: ‎06-15-2012
My Device: 9800
My Carrier: XZY

Create background listener

 

Hi,

            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.

 

Thanks

 

Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: Create background listener

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  

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: Create background listener

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:

https://developer.blackberry.com/services/push/

 

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:

http://supportforums.blackberry.com/t5/Java-Development/Create-a-Background-Application/ta-p/445226

 

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:

http://supportforums.blackberry.com/t5/Java-Development/Set-up-an-alternate-entry-point-for-an-appli...

I think you might also find this useful

http://supportforums.blackberry.com/t5/Java-Development/Allow-a-background-listener-to-detect-and-up...

 

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. 

Developer
Posts: 59
Registered: ‎06-15-2012
My Device: 9800
My Carrier: XZY

Re: Create background listener

 

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 .

 

Thanks

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: Create background listener

".... 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:

http://devblog.blackberry.com/2010/03/introducing-blackberry-push-services-to-developers/

and

http://bloc.eurion.net/archives/2010/sending-messages-to-blackberry-push-api-from-php/