Javascript 到 Android 在 worklight 中调用

Javascript to Android call in worklight

在 worklight 中,我使用 WL.NativePage.show 进行 android 本机调用。因为我在 activity(native) 中做了很多处理,所以它抛出错误 "The application may be doing too much work on its main thread".

作为解决方案,我使用线程进行计算(如此多的过程)并且它工作正常。但是在这种情况下,本机页面出现了。

但我只想在不渲染的情况下对本机输入(来自 JS)和输出(在 JS)进行一些计算 activity。

 ...

    public class EmbeddedCalculator extends Activity {

        public static Boolean isSuccessful = false;
        private Calculation calculation = new Calculation();
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    //  .. calculation - Higher process ..
                }
            };
            Thread t= new Thread(runnable);
            t.start();
        }
    }

那为什么要使用 WL.NativePage?

由于您没有提到您正在使用的 Worklight 的实际版本,我将只列出可能的替代方案:

  1. 创建将调用本机代码的 Cordova 插件,return 结果:https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/adding-native-functionality/ - 教程和示例可用
  2. 使用 SendAction API 调用本机代码(MobileFirst Platform Foundatin 6.3 及更高版本):http://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.dev.doc/devref/c_action_sender.html