如何退出编程方式从其他应用程序的黑莓应用程序吗? [英] How to exit a blackberry application from another application programatically?

查看:215
本文介绍了如何退出编程方式从其他应用程序的黑莓应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从其他应用程序编程退出黑莓应用程序。

How to Exit a blackberry application from another application programatically.

例如。在黑莓我安装两个应用比我更需要退出从第一个应用程序或退出,从我的应用程序另一个应用第二个应用程序。

e.g. In Blackberry i install two application than i need to exit on second application from first application or exit to another application from my application.

推荐答案

最清洁的方法恕我直言,是贯彻落实中要关闭应用程序接口 GlobalEventListener 。然后,从调用应用程序,发送一个全球性的事件有一些自己的定制code,让听音应用程序关闭自己在受控制的方式。

The cleanest approach IMHO is to implement the interface GlobalEventListener in the Application you want to close. Then, from the calling app, send a global event with some custom code of your own, and let the listening app to close itself in a controlled way.

例如:

在应用程序要关闭:

        public class YourCustomApp extends UiApplication implements GlobalEventListener {
            public static final long PID = <unique id for your app here>;
            public static final int CLOSE_APP_CODE = <your code here>;

            public void eventOccurred(long pid, int msgCode, int data1, Object object0, Object object1) {
                if(pid == PID){
                    switch(msgCode){
                        case CLOSE_APP_CODE:
                            controlledClose(); //This method could be, System.exit(0) if no other action is required
                            break;
                    }
                }
            }

        }

在调用应用程序:

        ApplicationManager.getApplicationManager().postGlobalEvent(PID, CLOSE_APP_CODE, 0, null, null);

在第二code片段中,你应该用正确的人取代int和long codeS。调用应用程序应该通过正确的价值观。你也可以放置在codeS在一个库中,让这两个应用使用的值从那里。确保PID为全系统唯一的,以便它不会不与系统中的其他应用发生冲突。一个好的做法是使用你的应用程序的完全合格的包名称,然后点击右键 - >在eclipse插件字符串转换为长

In the second code snippet, you should replace the int and long codes with the correct ones. The calling app should pass the correct values. You could also place the codes in a library and let both apps use the values from there. Make sure the PID is unique systemwide so that it does not not collide with other apps in the system. A good practice is to use the full qualified package name of your app and then right click -> "convert string to long" in eclipse plugin.

更新:结果
该哈克方式:您可以尝试使用EventInjection从您的应用程序中的组合键,可以关闭某个应用程序注入。例如,摄像头应用程序关闭时本身pressing ESC键。因此,我们可以尝试关闭它蒙山这一行:

UPDATE:
The hacky way: You can try using EventInjection to inject from your app the key combo that can close a certain app. For instance, the Camera app closes itself when pressing ESC key. So we could try to close it whith this line:

EventInjector.invokeEvent( new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN,Characters.ESCAPE, 0));

这做法是极不可靠。有时,它不工作,你可能通过增加短期视频下载需要微调注射每次注射事件发生后调用。或者,您可能需要调用从UI线程注入code。

This approach is extremely unreliable. Sometimes, it doesn't work, and you might need to fine tune the injection by adding short Thread.sleep calls after each injected event. Or you might need to call the injection code from the Ui thread.

记住要分配给您的应用程序的权限密钥注入。

Remember to assign to your app the permissions for key injection.

这篇关于如何退出编程方式从其他应用程序的黑莓应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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