Generally, the android applications we develop are based on activity and the Android system manages the life cycle of the program. However, sometimes we also want to control the process of the Program on our own. For example, if you only develop a console application like/system/bin/PM, it is not appropriate to use activity. Here I call this self-controlled process as a standalone Android program.
There is no big difference between the development method and the development of common Java applications. For example, we use Java's Hello, world! Program example:
Public class test {<br/> Public static void main (string [] ARGs) {<br/> system. Out. println ("Hello, world! /R/N "); <br/>}< br/>
We can compile it with javac to generate the. Class file:
Javac test. Java
At this time, we can run this program by running Java test, but for Android, we still need to convert it into a DEX file. We can use the DX tool in the android SDK to do this:
<SDK path>/platforms/Android-8/tools/dx -- Dex -- output = classes. jar test. Class
The usage of the DX tool is described here. DX -- Dex means to convert the. Class file to the DEX format. If the file name extension specified by -- output is. jar, the DX tool will also package it into a jar file for you. After this command is executed, we get a classes. jar file. You can see the file in jar tvf classes. jar:
72 Thu Dec 23 18:29:02 CST 2010 META-INF/manifest. MF
956 Thu Dec 23 18:29:02 CST 2010 classes. Dex
Now upload the classes. jar file to your mobile phone and run it on a virtual machine:
/System/bin/dalvikvm-classpath classes. jar test
This is to directly call the Dalvik Virtual Machine and specify it to run the main () entry function of the test class.
If you want to use the zygote Service to manage our applications, you can use app_process to start them. For example:
# Set classpath <br/> export classpath =/sdcard/classes. Jar <br/> # app_process <working dir> <Class Name> <br/> app_process/sdcard Test