Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

BlackBerry Push Development

Reply
Contributor
peterdeka
Posts: 39
Registered: 04-06-2011
My Carrier: Vodafone italy

PushApplication interface and normal app operation

Hi everyone it's a month now that i'm reading these forums and they helped me a lot in getting my app working, so first of all i want to greet an thank you.

 

Now i'm going into adding push functionality and since i'm developing for 5 and 6 apis i wanted to use the PushApplication interface instead of leaving my app running in the background. I studied a lot the example app that comes with the push sdk but i am not sure of how to make use of it.

 

In my app i want to raise a notification  when push arrives and then the user will open the app as usual from the menu and care about new info.

In the example the main doesn't care of how the app was launched(not uses entry points) so how do i know if i have to launch the ui or not(if the app was called by the push api)? In the example the main gets an uiapplication from pushlib that implements the pushapplication interface so receives the onmessage but i expected the main to handle this event....and then decide to launch or not the ui.. how does the api know that has to pass the pushstream to my uiapplication ? that is even not the same class as the one in which there is the main?

 

I'm a bit confused...please help me , thanks.

Please use plain text.
Developer
ekke
Posts: 393
Registered: 04-08-2010
My Carrier: vodafone, o2

Re: PushApplication interface and normal app operation

using OS 5 PushApplication API you can simply test at startup

 

isForeground()

 

if the app was started automatically by PushServices, then the app starts in background

 

----

if using OS 6 Communication API this is different: if app was autostarted from Push Receiver it's started in foreground.

ekke
independent software architect - eclipse, osgi, blackberry
blog: http://ekkescorner.wordpress.com/blog-series/blackberrydev/
videos: http://vimeo.com/channels/blackberrydev
apps: http://ekkes-apps.org
Please use plain text.
Contributor
peterdeka
Posts: 39
Registered: 04-06-2011
My Carrier: Vodafone italy

Re: PushApplication interface and normal app operation

Ok thanks, so the api starts my app in the main or in the onmessage function, this is what i can't understand.... because if it starts it in the onmessage method, i know that i've been waked by the api.... sorry if i ask but as most of us i'm still waiting for my push activation and my team cannot stop working and go on holiday just because we have to wait ages for a push service login :smileyvery-happy:

 

 

Please use plain text.
Developer
ekke
Posts: 393
Registered: 04-08-2010
My Carrier: vodafone, o2

Re: PushApplication interface and normal app operation

your App will always be started from main()

but if your App was started from Push Services, then you can ask ifForeground()

using OS 5 Push API it's false

 

(using OS 6 Communication API it's true, because - at the moment - 6.0 - Communication API starts always in foreground)

ekke
independent software architect - eclipse, osgi, blackberry
blog: http://ekkescorner.wordpress.com/blog-series/blackberrydev/
videos: http://vimeo.com/channels/blackberrydev
apps: http://ekkes-apps.org
Please use plain text.
Contributor
peterdeka
Posts: 39
Registered: 04-06-2011
My Carrier: Vodafone italy

Re: PushApplication interface and normal app operation

[ Edited ]

So why should i implement the pushapplication interface? when is the api calling my onMessage? only when the app is already running?

the flow for a closed app that is waked because a push for it arrived is this?

 

API->appMain and stop? no onMessage? so i wonder how to read a push message without polling!

 

thanks

Please use plain text.
Developer
ekke
Posts: 393
Registered: 04-08-2010
My Carrier: vodafone, o2

Re: PushApplication interface and normal app operation

the PUSH API is calling onMessage() if a Push message comes in

 

but if the APP wasn't started, at first the APP must be started - and this will be done by Push Service automagically

ekke
independent software architect - eclipse, osgi, blackberry
blog: http://ekkescorner.wordpress.com/blog-series/blackberrydev/
videos: http://vimeo.com/channels/blackberrydev
apps: http://ekkes-apps.org
Please use plain text.
Contributor
peterdeka
Posts: 39
Registered: 04-06-2011
My Carrier: Vodafone italy

Re: PushApplication interface and normal app operation

ok thanks, now it's clear. So if my app is closed, in my main, i check for foreground(api 5.0) and then in any case i must istantate the class that implements PushApplication(maybe telling it someway that it doesn't have to push any screen on constructor? ) and then i call enterEventDispatcher on it.

Is that right? so in api 6 how can one understand if main was called by pushapi?

 

However if i have a thread that keeps running in a while, my app stays open? or there is a way to keep it pen even if there was no screen pushed?

 

Thanks a lot

Please use plain text.
Developer
ekke
Posts: 393
Registered: 04-08-2010
My Carrier: vodafone, o2

Re: PushApplication interface and normal app operation

your Application implements PushApplication

 

if your App is not running then Push Service will autostart your Application in Background

you can test ifForeground() and if false you know app was started by Push Service

in Background and will process onMessage()

if your Message-processing doesn't require UI then the App can still remain in Background to wait for more messages from Push Service or -  if messages are rare you can exit the app after processing the messages

 

if App remains in Background and user later brings App to foreground you can detect this from

activate() <-- called if App comes from Back- to Foreground

and if activate() was called first time you can do your UI - dependend work

 

how your workflow looks like really depends from your logic what should happened after receiving messages

 

---

your question about OS 6 - Communication API:

you can still use OS 5 Network API under OS 6 - so if it's more comfortable for you if your app is in background, then use OS 5.

I'm working on some pure OS 6+ Apps where I try to use all OS 6 API .... still working on this ... let you know

ekke
independent software architect - eclipse, osgi, blackberry
blog: http://ekkescorner.wordpress.com/blog-series/blackberrydev/
videos: http://vimeo.com/channels/blackberrydev
apps: http://ekkes-apps.org
Please use plain text.
Contributor
peterdeka
Posts: 39
Registered: 04-06-2011
My Carrier: Vodafone italy

Re: PushApplication interface and normal app operation

Ok so i got my evaluation account and i can correctly subscribe the app when starts using the 5.0 push api, i also get the onStatusChanged callback function in my main class called and the status is "active". 

However when i send a push to the device,the server response is 1001, the arrows in the upper right corner show but the onMessage callback function doesn't get called (nothing, i set a breakpoint ). Is there anything i could be missing? the app is the debug version but i don't think it's a problem, i also uninstalled and reinstalled but same behavior..

 

Thanks

Please use plain text.
Developer
ekke
Posts: 393
Registered: 04-08-2010
My Carrier: vodafone, o2

Re: PushApplication interface and normal app operation

if you query from your content server - is the device listed as "Active" ?

ekke
independent software architect - eclipse, osgi, blackberry
blog: http://ekkescorner.wordpress.com/blog-series/blackberrydev/
videos: http://vimeo.com/channels/blackberrydev
apps: http://ekkes-apps.org
Please use plain text.