在Codename中访问和使用一个原生Android类 [英] Access and use in Codename One native Android classes
问题描述
我知道Codename One和Android是完全不同的框架。但是问题是,如何从本地Android中访问Codename One类?
I know that Codename One and Android are completely different frameworks. But the question is, How can I access in Codename One classes from native Android?
例如:我想创建一个名为 onCreat()的方法
看起来像这样:
eg: I want to create a method called onCreat()
that looks like this:
public void onCreate(Bundle savedInstanceState){}
在Android中,您必须导入软件包 import android.os.Bundle;
In Android you have to import the package import android.os.Bundle;
如何集成此程序包(用于 onCreat()
)和其他Android程序包中的代号One ?
How can I integrate this package (for onCreat()
) and other packages from Android in codenamed One?
我应该在Code Name One中设置什么才能访问这些类。
What should I set in Code Name One that I can access these classes. Is this possible?
编辑:
另一个示例:
import android.net.Uri;
public void startWeb(View v) {
Uri uri = Uri.parse("http://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
我该如何在Codename One中转换此Android代码,使其看起来像这样并且,如果我单击按钮,则可以正常工作:
How can i convert this Android code in Codename One so that it looks like this and, if i click on the Button, works:
protected void onMain_Button6Action(Component c, ActionEvent event) {
Uri uri = Uri.parse("http://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
重点是我想了解如何制作代号的Android代码一种功能。
The point is that I want to understand how I make the Android code for Codename One functional.
谢谢。
推荐答案
您需要使用< a href = http://www.codenameone.com/how-do-i---access-native-device-functionality-invoke-native-interfaces.html rel = nofollow>原生接口访问android原生功能。但是,onCreate调用是一种特殊情况,因为它是Android应用程序生命周期中的回调,将被调用以启动Codename One的start / init方法,并且不会调用您的代码。
You need to use native interfaces to access the android native functionality. However, the onCreate call is a special case since its a callback from the lifecycle of the Android application and will be invoked to launch the Codename One start/init methods and will not invoke your code.
要收听这些生命周期调用,可以使用AndroidNativeUtil类,该类具有一个生命周期侦听器,可让您从本机接口访问这些功能。
To listen to those lifecycle calls you can use the AndroidNativeUtil class which has a lifecycle listener that allows you to access those features from the native interfaces.
这篇关于在Codename中访问和使用一个原生Android类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!