Codenameone CN1库-runOnUiThread中无代码激发

Codenameone CN1库-runOnUiThread中无代码激发,codenameone,Codenameone,本机实现中没有在runOnUiThread中触发代码。RunNuithRead启动前的代码。我肯定我做的事情不对。 我像这样创建了CodenameOne库 package com.uithread.test; import com.codename1.system.NativeInterface; public interface UIThreadNative extends NativeInterface { public void runNativeCode(); } pac

本机实现中没有在runOnUiThread中触发代码。RunNuithRead启动前的代码。我肯定我做的事情不对。 我像这样创建了CodenameOne库

package com.uithread.test;

import com.codename1.system.NativeInterface;

public interface UIThreadNative extends NativeInterface {

    public void runNativeCode();
}

package com.uithread.test;

import com.codename1.system.NativeLookup;
import com.codename1.ui.Dialog;

public class UIThreadManager {

private static UIThreadNative uithreadNative;

public UIThreadManager() {
    if (uithreadNative == null) {
        uithreadNative = (UIThreadNative) NativeLookup.create(UIThreadNative.class);
        if (uithreadNative == null) {
            Dialog.show("Null implementation", " UIThread is not implemented yet in this platform.", "Ok", null);

            throw new RuntimeException("UIThread is not implemented yet in this platform.");
        }
    }
    if (!uithreadNative.isSupported()) {
        Dialog.show("Unsupported", " UIThread is not supported in this platform.", "Ok", null);
        throw new RuntimeException("UIThread is not supported in this platform.");
    }
}

public void runNativeCode() {
    uithreadNative.runNativeCode();
}

}
android的本机实现

package com.uithread.test;

import android.content.Context;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.codename1.impl.android.*;
import com.codename1.ui.Dialog;

public class UIThreadNativeImpl {

private static Context context() {
    return com.codename1.impl.android.AndroidNativeUtil.getActivity().getApplicationContext();
}

private static Activity activity() {
    return com.codename1.impl.android.AndroidNativeUtil.getActivity();
}

public void runNativeCode() {
    final Activity convenientActivity = activity();//AndroidNativeUtil.getActivity();
    final CodenameOneActivity codenameoneActivity = (CodenameOneActivity) AndroidNativeUtil.getActivity();
    final android.app.Activity app = (Activity) AndroidNativeUtil.getActivity();

    Dialog.show("Activity", convenientActivity + " convenientActivity", "Ok", null);
    Dialog.show("Activity", codenameoneActivity + " codenameoneActivity", "Ok", null);
    Dialog.show("Activity", app + " App", "Ok", null);

    convenientActivity.runOnUiThread(new Runnable() {

        public void run() {
            Dialog.show("In run", "Run started", "Ok", null);
        }
    });
}

public boolean isSupported() {
    return true;
}

}
在Statemachine中,我通过单击按钮在代码中运行此命令

@Override
protected void onMain_ButtonAction(Component c, ActionEvent event) {
    UIThreadManager uIThreadManager = new UIThreadManager();
    uIThreadManager.runNativeCode();
}
正如我刚才所说。runOnUiThread之前的代码工作,但runOnUiThread中的代码不工作。本机实现中runNativeCode中的对话框用于检查不同风格的活动,这正确地显示了不同的风格是相同的


谢谢。

本机UI线程与我们的EDT完全不同,因此从该线程显示一个代号为One的对话框将是一个巨大的EDT冲突,可能会导致严重的崩溃

由于我们的对话框可以安全地阻止,因此您将有效地阻止整个应用程序并使其崩溃

我们使用的这一行与您在Codename One和库中编写的内容非常相似,例如:


谢谢。救了我一天。所有android本机代码都能完美启动。
AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() { ... });