黑莓 - 如何在电话启动开始自己的服务? [英] Blackberry - how to start my own service at phone boot-up?

查看:176
本文介绍了黑莓 - 如何在电话启动开始自己的服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开始我自己的服务实现当手机开始?

如何实现呢?


解决方案

引自<一个href=\"http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/832062/How%5FTo%5F-%5FWrite%5Fsafe%5Finitialization%5F$c$c.html?nodeid=1487426&vernum=0\"相对=nofollow>如何 - 编写安全的初始化code


  

这是应用程序可能需要系统在一次自动运行启动时执行初始化程序,如注册监听器和持久化存储检索信息。


  
  直到系统完成核心启动任务,如安全检查,建立网络连接,并执行其他任务不应该执行

这种例程。


  
  

因此​​,一个应用程序应该确保系统启动完成后运行其自己的初始化code之前,如下面的例子所示:


 类实现的MyApp {SystemListener
    公共静态无效的主要(字串[] args){
    MyApp的appInstance =新MyApp的();
    //如果系统启动时仍在进行中时,这个
    //运行应用程序。
    如果(ApplicationManager.getApplicationManager()。inStartup()){
    appInstance.addSystemListener(appInstance);
    }其他{
    appInstance.doStartupWorkLater();
    }
    appInstance.enterEventDispatcher();
    }
    // 结构体
    MyApp的(){
    }
    私人无效doStartupWorkLater(){
    的invokeLater(Runnable的新(){
    公共无效的run(){
    doStartupWork();
    }
    });
    }
    私人无效doStartupWork(){
    }
    // SystemListener
    公共无效通电(){
    removeSystemListener(本);
    doStartupWork();
    }
    // TODO:其他SystemListener方法
}

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

How to achieve it?

解决方案

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
}

这篇关于黑莓 - 如何在电话启动开始自己的服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆