Blackberry - How to get the background application

2019-03-22 00:19发布

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.

3条回答
乱世女痞
2楼-- · 2019-03-22 00:36

List and switch visible application

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]));
    }
}
查看更多
狗以群分
3楼-- · 2019-03-22 00:43

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!

查看更多
爷的心禁止访问
4楼-- · 2019-03-22 00:53

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

查看更多
登录 后发表回答