Blackberry - How to get the background application process id

↘锁芯ラ 提交于 2019-12-09 07:03:25

问题


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



来源:https://stackoverflow.com/questions/1090929/blackberry-how-to-get-the-background-application-process-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!