将 java 应用程序移植到 Android 平台

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1575892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 16:24:50  来源:igfitidea点击:

Porting java apps to Android platform

javaandroiduser-interfaceporting

提问by GotAmye

I know Java apps can be run in Android. But what I want to know is this: I have a perfectly normal Java app and I want to port it to an android platform. What changes would I need to do to my app in terms of GUI and other code to make it usable in Android? I know Android uses XML file to control the look and feel of its app. So would I need to change my GUI completely?

I just want to know the general overview of how porting may be done. If anyone could point me to right resources, that would be great. Also, for your info I'm a newbie to developing android app, so please be patient with me :)

我知道 Java 应用程序可以在 Android 中运行。但我想知道的是:我有一个完全正常的 Java 应用程序,我想将它移植到 android 平台。我需要在 GUI 和其他代码方面对我的应用程序进行哪些更改才能使其在 Android 中可用?我知道 Android 使用 XML 文件来控制其应用程序的外观。那么我需要完全改变我的 GUI 吗?

我只想知道如何进行移植的一般概述。如果有人能指出我正确的资源,那就太好了。另外,对于您的信息,我是开发 android 应用程序的新手,所以请耐心等待我:)

Update: Both very helpful answers. Thank you!

更新:两个非常有用的答案。谢谢!

采纳答案by Sean Owen

The short answer is that you would simply rewrite all of the GUI from scratch, for Android. It simply uses a completely different UI framework. While basically all of the core Java libraries are there, Swing and AWT libraries are not.

简短的回答是,您只需从头开始为 Android 重写所有 GUI。它只是使用了一个完全不同的 UI 框架。虽然基本上所有的核心 Java 库都在那里,但 Swing 和 AWT 库却没有。

If you are looking to translate parts of it automatically, I don't think there is any such tool. You're going to be building a brand new Android GUI.

如果您希望自动翻译其中的一部分,我认为没有任何此类工具。您将构建一个全新的 Android GUI。

And really, that makes sense. These frameworks are serving reasonably different platforms and needs (desktop vs. phone). You probably need to be redesigning your app quite a bit to go from a desktop to a phone.

真的,这是有道理的。这些框架服务于相当不同的平台和需求(桌面与手机)。你可能需要重新设计你的应用程序,才能从桌面到手机。

Good news is the non-GUI parts ought to work as-is with no changes, unless they do something unusual. You may have to package third party libraries into your project if they are used by your code.

好消息是非 GUI 部分应该按原样工作,不做任何更改,除非它们做了一些不寻常的事情。如果您的代码使用第三方库,您可能需要将它们打包到您的项目中。

回答by James Black

I expect that it will be a great deal of work to do the porting, as the way that your application works with Android will be different.

我预计移植需要大量工作,因为您的应用程序与 Android 的工作方式会有所不同。

You will also have some issues, perhaps, with the fact that not everything in java is supported, as it is a mobile device, but does more than JavaME.

您可能还会遇到一些问题,因为并非 Java 中的所有内容都受支持,因为它是一种移动设备,但比 JavaME 做得更多。

It would help if you could explain a bit about the application, as how much it needs to interact with the user or any other resources on the device will determine how to port and how much work is involved.

如果您能对应用程序进行一些解释,将会有所帮助,因为它需要与用户或设备上的任何其他资源交互的程度将决定如何移植以及涉及多少工作。

Your best bet though is to see about learning to program on the Android, and there are several good books on the subject. I got one from Manning publications that I found helpful.

不过,最好的办法是了解如何在 Android 上学习编程,并且有几本关于该主题的好书。我从曼宁的出版物中得到了一份我觉得很有帮助的书。

You may want to look at the comments in this article, as I think it would be a good starting point for you on what may need to be changed: http://www.anddev.org/problem_in_android_project_conversion-t1633.html

您可能想查看本文中的评论,因为我认为这对您可能需要更改的内容是一个很好的起点:http: //www.anddev.org/problem_in_android_project_conversion-t1633.html