如何识别应用程序是否在后台运行

问题描述:

我有一个应用程序在点击应用程序图标(即进入应用程序时)时询问密码。然后我设置了UiApplication.getUiApplication()。requestBackground();应用程序在后台运行。如何识别应用程序是否在后台运行

现在如果再次进入应用程序意味着它要求密码。

帮帮我吧。

与问候, 萨姆帕斯

您可以使用UiApplication.getUiApplication()。isForeground()方法来确定,如果你的应用程序是在前台。

isForeground方法继承自net.rim.device.api.system应用程序类,它也支持requestForeground和requestBackground方法。

http://www.blackberry.com/developers/docs/4.6.0api/net/rim/device/api/ui/UiApplication.html

我想你可能有兴趣在Application.activate()方法:

public void activate() 

// Handles foregrounding event. 

// The system invokes this method when it brings this application 
// to the foreground. By default, this method does nothing. 
// Override this method to perform additional processing 
// when being brought to the foreground. 

UiApplication扩展Application所以这种方法也是你UiApplication子类可用。