Detect when an application or screen moves to the foreground or background

by Retired ‎02-16-2010 12:20 PM - edited ‎09-16-2010 02:28 PM (5,162 Views)



This article applies to BlackBerry® devices based on Java®.




An application is able to determine if it is in the foreground or background using the UiApplication.isForeground() method. This method will return true if the application is in the foreground, or false if it is not. The UiApplication.activate() and UiApplication.deactivate() methods can also be overridden to allow an application to be notified when such a change takes place. The activate method is called when an application is brought to the foreground. The deactivate method is called when an application is sent to the background.


Screens may also be notified when they move to the foreground (become visible) or when they move to the background (become not visible or are wholly or partially obscured by another screen). When a screen becomes visible to the BlackBerry device user, the Screen.onExposed() method is called. When a screen becomes partially or wholly obscured by another screen, the Screen.onObscured() method is called.


Graphically intensive applications should make use of these methods to determine when a screen is no longer visible and disable or pause any rendering or animation actions they are performing.