In my blackberry simulator i m running two application at the background now i want to retrive which are the application running in the background.I don't how to do. Is it possible to show which are the application running in the background.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
List and switch visible application
- To list all visible applications use ApplicationManager.getVisibleApplications()
- To bring some application foreground use ApplicationManager.requestForeground(processId)
alt text http://img195.imageshack.us/img195/7003/applist.png link text http://img32.imageshack.us/img32/9273/applistmenu.png
Code:
class Scr extends MainScreen {
ApplicationDescriptor[] mAppDes;
public Scr() {
listApplications();
}
void listApplications() {
ApplicationManager appMan =
ApplicationManager.getApplicationManager();
mAppDes = appMan.getVisibleApplications();
add(new LabelField("Visible Applications:"));
for (int i = 0; i < mAppDes.length; i++) {
boolean isFG = appMan.getProcessId(mAppDes[i]) == appMan
.getForegroundProcessId();
String text = (isFG ? "[F]:" : "[B]") + mAppDes[i].getName();
add(new LabelField(text));
}
}
protected void makeMenu(Menu menu, int instance) {
super.makeMenu(menu, instance);
menu.add(refreshApps);
makeAppMenuItems(menu);
}
MenuItem refreshApps = new MenuItem("Refresh", 0, 0) {
public void run() {
deleteAll();
listApplications();
}
};
class AppMenuItem extends MenuItem {
ApplicationDescriptor mAppDes;
public AppMenuItem(ApplicationDescriptor appDes) {
super(appDes.getName(), 100000, 100000);
mAppDes = appDes;
}
public void run() {
ApplicationManager appMan = ApplicationManager
.getApplicationManager();
int processId = appMan.getProcessId(mAppDes);
appMan.requestForeground(processId);
}
}
void makeAppMenuItems(Menu menu) {
for (int i = 0, cnt = mAppDes.length; i < cnt; i++)
menu.add(new AppMenuItem(mAppDes[i]));
}
}
回答2:
Take a look at the API Reference for the RuntimeStore.
And a Knowledge Base entry how to switch an App to the Background/Foreground.
Good Luck!
回答3:
Not really an answer, but the system won't let me comment.
Do you really need to know what the running background applications are, or just if your applications are running in the background. If the latter I imagine you can build something using the runtime store