黑莓 - 如何在手机启动时启动我自己的服务?

发布于 2024-08-05 14:31:38 字数 39 浏览 5 评论 0原文

我想在手机启动时启动自己的服务实现?

如何实现?

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

How to achieve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沉鱼一梦 2024-08-12 14:31:38

您只需在blackberry JDE 中的项目属性中设置“系统模块”和“自动启动”选项即可。这将在手机启动时启动您的应用程序。

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.

绮筵 2024-08-12 14:31:38

引用自 如何 - 编写安全初始化代码

应用程序可能需要在系统启动期间自动运行一次,以执行初始化例程,例如注册侦听器和从持久存储中检索信息。

在系统完成核心启动任务(例如安全检查、建立网络连接和其他任务)之前,不应执行此类例程。

因此,应用程序应在运行自己的初始化代码之前确保系统启动完成,如以下示例所示:

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
}

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
}
旧情别恋 2024-08-12 14:31:38

您可以使用 IPC(某种)机制在“服务”和应用程序之间交换数据。有两种方法可以实现此目的:

  1. net.rim.device.api.system.RuntimeStore 具有放置和获取由唯一 id(长整型)标识的对象的方法。该 ID 可以从 JDE IDE 中生成。
  2. net.rim.device.api.system.ApplicationManager 具有允许发布全局事件的方法,这些事件可以交换数据(再次由唯一 id 标识)。另一个应用程序必须实现 GlobalEventListener 并向系统注册 - addGlobalEventListener。

在第一种方法中,当将数据添加到存储时,不会通知其他实体。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文