Blackberry - how to start my own service at phone boot-up?

不羁岁月 提交于 2019-11-29 15:52:11

问题


I want to start my own service implementation when the phone starts?

How to achieve it?


回答1:


You just need to set the "System Module" and "Auto Start" options in the project properties in the blackberry JDE. This will start your app on phone boot.




回答2:


Quote from How To - Write safe initialization code

An application may need to run once automatically during system start-up to perform initialization routines such as registering listeners and retrieving information from persistent storage.

Such routines should not be performed until the system has finished core start-up tasks such as security checks, establishing network connectivity, and other tasks.

Therefore an application should ensure that system start-up is complete before running its own initialization code, as demonstrated in the following example:

class MyApp implements SystemListener {
    public static void main(String[] args) {
        MyApp appInstance = new MyApp();
        // If system startup is still in progress when this
        // application is run.
        if (ApplicationManager.getApplicationManager().inStartup()) {
            appInstance.addSystemListener(appInstance);
        } else {
            appInstance.doStartupWorkLater();
        }
        appInstance.enterEventDispatcher();
    }
    // constructs
    MyApp() {
    }   
    private void doStartupWorkLater() {
        invokeLater(new Runnable() {
            public void run() {
                doStartupWork();
            }
        });
    }  
    private void doStartupWork() {
    }    
    // SystemListener
    public void powerUp() {
        removeSystemListener(this);
        doStartupWork();
    }
    // TODO: other SystemListener methods
}



回答3:


You could use an IPC (kind of) mechanism to exchange data between the "Service" and Application. There are two ways of accomplishing this:

  1. net.rim.device.api.system.RuntimeStore has methods to put and get an Object that is identified by an unique id (long). This id can be generated from within the JDE IDE.
  2. net.rim.device.api.system.ApplicationManager has methods that allows one to post global events, that can exchange data (once again identified by unique id). The other application will have to implement GlobalEventListener and register with the system - addGlobalEventListener.

In the first approach, the other entity is not notified when data is added to store.



来源:https://stackoverflow.com/questions/1445172/blackberry-how-to-start-my-own-service-at-phone-boot-up

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