Blackberry - 如何获取后台应用程序进程ID

时间:2009-07-07 07:58:53

标签: blackberry integration background-application

在我的黑莓模拟器中,我在后台运行两个应用程序,现在我想要检索哪些是在后台运行的应用程序。我不知道怎么做。是否可以显示在后台运行的应用程序。

3 个答案:

答案 0 :(得分:7)

列出并切换可见应用程序

alt text http://img195.imageshack.us/img195/7003/applist.png link text http://img32.imageshack.us/img32/9273/applistmenu.png

代码:

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]));
    }
}

答案 1 :(得分:2)

查看RuntimeStore的API参考。

Knowledge Base entry如何将应用切换到背景/前景。

祝你好运!

答案 2 :(得分:1)

不是真的答案,但系统不会让我评论。

您真的需要知道正在运行的后台应用程序是什么,或者您的应用程序是否在后台运行。如果是后者,我想你可以使用运行时商店构建一些东西

相关问题