我正在使用 codenameone,我需要在 android 中执行一些本机代码,但这会影响更改内容视图,当我尝试让应用程序返回到 codenameone 表单时,使用本机代码我最终会出现白屏,
无论如何,我可以使用代号处理从安卓本机代码导航showForm
?
尝试下面的评论后,这里是模拟案例时应用程序的日志猫:
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.mycompany.myapp/.MyApplicationStub bnds=[540,672][786,960]} from uid 10010 on display 0 from pid 1738
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Start proc 31254:com.mycompany.myapp/u0a352 for activity com.mycompany.myapp/.MyApplicationStub
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Gaining focus: Window{252c6842 u0 com.mycompany.myapp/com.mycompany.myapp.MyApplicationStub}
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): [AppLaunch] Displayed Displayed com.mycompany.myapp/.MyApplicationStub: +335ms
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Thread[1,tid=31254,WaitingForJniOnLoad,Thread*=0x7facc9a000,peer=0x760befb0,"main"] recursive attempt to load library "/data/app/com.mycompany.myapp-1/lib/arm64/libopentok.so"
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Thread[1,tid=31254,WaitingForJniOnLoad,Thread*=0x7facc9a000,peer=0x760befb0,"main"] recursive attempt to load library "/data/app/com.mycompany.myapp-1/lib/arm64/libopentok.so"
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Thread[1,tid=31254,WaitingForJniOnLoad,Thread*=0x7facc9a000,peer=0x760befb0,"main"] recursive attempt to load library "/data/app/com.mycompany.myapp-1/lib/arm64/libopentok.so"
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Thread[1,tid=31254,WaitingForJniOnLoad,Thread*=0x7facc9a000,peer=0x760befb0,"main"] recursive attempt to load library "/data/app/com.mycompany.myapp-1/lib/arm64/libopentok.so"
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Thread[1,tid=31254,WaitingForJniOnLoad,Thread*=0x7facc9a000,peer=0x760befb0,"main"] recursive attempt to load library "/data/app/com.mycompany.myapp-1/lib/arm64/libopentok.so"
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): setMode: mode = 3; packageName = com.mycompany.myapp
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): setMode: mode = 0; packageName = com.mycompany.myapp
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at com.mycompany.myapp.VideoChat$1.run(Unknown Source)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Process: com.mycompany.myapp, PID: 31254
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): at com.mycompany.myapp.NativeVideoChatImpl$VideoChat$4.onClick(NativeVideoChatImpl.java:234)
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Force finishing activity 1 com.mycompany.myapp/.MyApplicationStub
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Losing focus: Window{252c6842 u0 com.mycompany.myapp/com.mycompany.myapp.MyApplicationStub}
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Process com.mycompany.myapp (pid 31254) has died
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): channel '252c6842 com.mycompany.myapp/com.mycompany.myapp.MyApplicationStub (server)' ~ Consumer closed input channel or an error occurred. events=0x9
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): channel '252c6842 com.mycompany.myapp/com.mycompany.myapp.MyApplicationStub (server)' ~ Channel is unrecoverably broken and will be disposed!
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): WIN DEATH: Window{252c6842 u0 com.mycompany.myapp/com.mycompany.myapp.MyApplicationStub}
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Attempted to unregister already unregistered input channel '252c6842 com.mycompany.myapp/com.mycompany.myapp.MyApplicationStub (server)'
请参阅开发人员指南中标题为"本机代码回调"的高级部分。
创建一个静态方法,例如showForm()
在创建窗体的类中。在您的原生 Android 代码中,您可以使用实现该方法的类的完整包名称调用该方法,例如:com.mycompany.myapp.MyFormClass.showForm()
.
然后,实现该方法的类需要具有对窗体的引用,因此它可以是创建窗体并保持对窗体的静态引用的类。为了保留内存,您可能希望在窗体被关闭时释放引用。
在iOS和其他平台中,请遵循开发人员指南中的指南,例如,在这种情况下,对于iOS,showForm()
如下所示(在.m
文件的顶部):
#include "com_mycompany_myapp_MyFormClass.h"
然后当你想打电话给showForm()
:
com_mycompany_myapp_MyFormClass_showForm__(CN1_THREAD_STATE_PASS_SINGLE_ARG);
在尝试了所有senarios之后,我注意到它实际上回到了表单,但没有显示内容,所以这是我在另一个应用程序中遇到此问题后所做的, 代码是在本地实现的 - 试图改变时间段,当我少走时,问题又回来了,所以这对我来说已经足够了
getActivity().finish();
intent = new Intent(getContext(), MyApplicationStub.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
handler = new Handler();
timer = new Timer();
initializeTimerTask();
timer.schedule(timerTask, 500);
public void initializeTimerTask() {
timerTask = new TimerTask() {
public void run() {
//use a handler to run a toast that shows the current timestamp
handler.post(new Runnable() {
public void run() {
getContext().startActivity(intent);
}
});
}
};
}
感谢您所有的帮助@JamesH和@Shai