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

Native Development

Reply
Highlighted
Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany
Accepted Solution

Discern between fullscreen and waking up

My app has to do some background stuff when it was thumbnailed and the user returns to it.

 

To do that i connected the fullscreen signal:

https://developer.blackberry.com/cascades/reference/bb__cascades__application.html#function-fullscre...

 

however, this signal seems to be called whenever the screen black and i "wake up" the device.

This happens a lot more frequently, any idea how i could discern these events?

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: Discern between fullscreen and waking up

Check the awake, invisble and sleep signals ...

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Discern between fullscreen and waking up

Seconding the suggestion to look at "awake" and "asleep". For a purpose similar to yours, simon_hain, they worked out better for me than using fullscreen etc.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Discern between fullscreen and waking up

I checked awake and asleep, but the thing is that i do NOT want to have my code trigger at these states, only when the application was switched out of and the user returns to it.

I tried to use a flag in onThumbnail, but the stupid system also calls this slot when i wake up my device.

How can i discern between the user switching back from another app (task switcher) and the user just waking up the device?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: Discern between fullscreen and waking up

for me this seems like a bug calling minimized and fullscreen from awake and asleep

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Discern between fullscreen and waking up

[ Edited ]

ekke wrote:

for me this seems like a bug calling minimized and fullscreen from awake and asleep


Yes, at least that is how i understand the signal description.

 

I have found a workaround:

I use onProcessStateChanged and save the last state. If the new state is 1 (Foreground) and the last state 2 (Background) i trigger my processing. When the screen goes dark the app goes to state 3 (Stopping), so i can discern between these.

 

I'll also post a bug report about the onThumbnail/onFullScreen signals.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Discern between fullscreen and waking up

If you're going to rely on processStateChanged, please test it thoroughly. I was exploring these signals extensively last week and had to give up on processStateChanged, as it didn't reliably deliver the signals at all times I thought it should. Specifically I was sometimes able to wake the app up, then put it back in the background, without getting signals reporting either of those.

Also, the stopping signal will be delivered not just when the screen goes dark, but also a few seconds after you switch away from the app, such as by going to the Hub or the app icon pages.

If you don't want the app to do your special handling when the device sleeps, then I think you'll need to monitor both the window state events and the asleep/awake events, and basically filter out the window ones when you're also getting "asleep". Alternatively, use a very short timer on the window state events, and react to them only if you don't get another one that contradicts the first one within 50ms or so.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: Discern between fullscreen and waking up

Peter and Simon,

thanks for all the infos on these different signals.

I also have to do some work in one of my apps depending from foreground/background -

your hints are really useful

 

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Discern between fullscreen and waking up

[ Edited ]

In my tests it's been successful so far. There is a delay until the Background-State is reported (~5 seconds), but that suits my purpose.
The state also switches from 3 to 2 when the app is thumbnailed, the device sleeps and is woken up again.

Debug: 13:06:01.858 onProcessStateChanged 2 <-thumbnailed
Debug: 13:06:32.752 onProcessStateChanged 3 <- screen timeout
Debug: 13:06:49.747 onProcessStateChanged 2 <- wake up

 

edit:

created https://www.blackberry.com/jira/browse/BBTEN-1484

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Discern between fullscreen and waking up


simon_hain wrote:

In my tests it's been successful so far. There is a delay until the Background-State is reported (~5 seconds), but that suits my purpose.


Just keep stress testing. I spent over an hour on this and it was definitely broken from my point of view. I can reproduce the issue again when I get a chance, maybe next week. I think it occurred when I switched away (to icons page) and waited a few seconds but not long enough for the stopped signal to be issued, then back.

 

(The use of the run_when_backgrounded flag can affect this, but as I recall using it means you simply never get the stopped signal.)

 

Basically, if it's very important that this reliably signal you, please don't assume based on limited testing that it will really work for you.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!