Is it possible to write a plain old java program that runs on android?

I see tutorials that show you how to make a real android application with activities and all that, but all I really want to do is make a java class that has a public void static main(String params[]) { System.out.println("Hello World");} and run it with java HelloWorld on an android machine. Is that possible?


There's a great app on the Android market called Terminal IDE that includes a great shell environment, vim/nano and java/javac all compiled to run natively on Android. With this you can run "normal" Java code.


Actually, if you take the time to create a very simple Activity (which Eclipse will basically generate for you when you make a new Android application, then you will be able to create and call any class or method on that class that you so desire.

In the Activity class, there will be a method called create() - you will modify it to instantiate your class and call a desired method...

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Instantiate your class or simply call its main(String[] args) method here 
}

There, that wasn't so hard was it?

Good Luck!

Rodney

链接地址: http://www.djcxy.com/p/96752.html

上一篇: 编译src中的所有文件?

下一篇: 是否有可能编写一个在android上运行的普通旧java程序?