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: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus
Accepted Solution

Check if application is in foreground

Hello everyone. My app runs in the background and has a GPS listener and phonelistener. I created an eventinjector to ignore incoming calls (supposed to only ignore calls when the app is in the foreground) but it also ignores calls when the app is in the background. I tried

if(this.isDisplayed()){
//Injector code
}else{
//Do nothing
}

But it's not working, the app continues to ignore all incoming calls even when it's in the background.
Developer
Posts: 16,838
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Check if application is in foreground

http://www.blackberry.com/developers/docs/7.0.0api/net/rim/device/api/system/Application.html#isFore...
----------------------------------------------------------
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: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Check if application is in foreground

One more thing to be aware of - if you code snippet above is running in the context of the phone listener, the you are not checking the status of *your* application. These listeners run in the context of the calling application.

 

Developer
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus

Re: Check if application is in foreground

Rex I think simon alluded to this in another post I made, do you mean I should create a custom listener that extends PhoneListener? Not really sure what you mean.
Developer
Posts: 16,838
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Check if application is in foreground

what i do:
send a global event in the phonelistener. receive it in your app.
this switches the context to your app.
----------------------------------------------------------
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: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus

Re: Check if application is in foreground

Thanks simon now I get it Smiley Very Happy
New Contributor
Posts: 7
Registered: ‎05-10-2011
My Device: 8310
My Carrier: TMUS

Re: Check if application is in foreground

Hello,

 

 

I am developing a game for blackberry using MIDP.

 

I want to pause my game when Switch Application menu appear when OEM menu button hold. I put following code In main looping  to check is Application foreground or not.

 

 

        if(  ! Application.getApplication( ).isForeground( ) )
        {
            hideNotify( );
        }
        else
        {
            if(  ! hasNotified )
            {
                hasNotified = true;
                showNotify( );
            }
        }

 

It work for Firmware above 4.6 but not for 4.6 and below.

I try to trace use JDE 4.6 and found the value of

 

Application.getApplication( ).isForeground( )

 

was always true except after App mimized.

 

Anyone ever facing this issue?

 

 

Thank You,


Hasyim

Developer
Posts: 16,838
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Check if application is in foreground

please open a new thread with your problem
----------------------------------------------------------
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
Highlighted
New Contributor
Posts: 7
Registered: ‎05-10-2011
My Device: 8310
My Carrier: TMUS

Re: Check if application is in foreground

Ok. Thx.