我正在使用codenameone,我需要在android中执行一些本机代码,但是我想要更改内容视图,当我尝试让应用程序返回到codenameone表单时,使用本机代码我最终会使用白色屏幕,
无论如何,我可以使用showForm
代号从android本机代码处理导航?
在尝试下面的评论后,这里是应用程序的日志cat,同时模拟案例:
??-?? ??:??:??.???: 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)'
答案 0 :(得分:3)
请参阅标题为“本机代码回调”的advanced section in the developer guide。
创建静态方法,例如您创建表单的类中的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);
答案 1 :(得分:0)
在尝试了所有的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