I have successfully developed a BlackBerry App that registers for BlackBerry Push Messaging Service
and receives push message. The Push Message
is received as a pop-up message. I am handling at the back end to show this message inside the App in a Chat Screen
that I have created. The push message when sent to the device is stored in a database as well. The App has a timer running that queries the database for any new message and displays it inside the app. However this approach is not so efficient as I aim to display the message as soon as it is sent as a push message. My questions are as follow:
- When the App is closed and the server sends a push message, will this message be delivered?
- When a push message is received, how do you force-start an app?
- Is there any particular API or method available to detect when a push message is received?
- I am able to change the App icon when a message is received. However, I want this to change as soon as the
push message
is received as the pop-up. So how can I detect when the push message
is received other than running a background timer?
Please guide.
I would agree that polling a database for new messages is not a good solution.
What I would do is to implement two entry points in your app:
1) A background process, that extends the BlackBerry Application
class. This is non-graphical, and will listen for push notifications.
2) A normal UI, which I think you're referring to as "the App". This will extend the UiApplication
class.
When your background process receives push notifications, you can then choose to open up the UiApplication
so your user can handle the new chat message.
To answer your questions:
Yes, the push notification will be received, because the background process is always running (you should make sure to check the Autorun at Startup box in the BlackBerry_App_Descriptor.xml file, for the background entry point). See more here.
The background process can bring the UI application to the foreground with this code.
There's multiple ways to receive push notifications ... see links below. It sounds like you already have this implemented. I think the key, though, is that you put your push handling code in the background Application
. Then, your UI application doesn't need any special APIs. Your background application simply opens the UI when it's time. It can choose to pass data to the UI application with this technique.
Again, you'll want to setup two entry points: one background Application
, and one normal UiApplication
. The background application will run on startup, register for push notifications, and receive push notifications as they come in (without polling). You can then decide what to do, including opening up your UI (UiApplication
).
More on Push and Entry Points
http://devblog.blackberry.com/2010/06/super-apps-java-series-running-in-the-background-part-1/
When you download the Push SDK, you'll find sample code in there.
Within the BlackBerry Eclipse Plugin, you can Import... -> Import BlackBerry Samples -> HTTPPushDemo for more demo source.
Tutorial: Making an app push-enabled (OS 6.0+)