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

后端 未结 3 964
自闭症患者
自闭症患者 2021-01-01 08:01

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

How to achieve it?

3条回答
  •  渐次进展
    2021-01-01 08:35

    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
    }
    

提交回复
热议问题