There are actually many ways to start JAVA programs in Android, which are summarized as follows:
1. Send Intent in the Android app to start the Android app
This method is the simplest and most commonly used. I will not describe it here. For more information about Intent, see Intent technology introduction.
2. Use the am command on the shell console to send Intent to start Android applications
In the Android shell console, use the am command to send Intent to start the Android Application.
For more information, see Android command am.
3. Run the davlikvm command on the shell console to start a JAVA program.
This method has a natural disadvantage, that is, many Android JNI cannot be called. Because many JNI of Android actually need to be manually registered.
For more information, see Basic Dalvik VM call.
4. Start a JAVA program directly on the shell console by running the app_process Program
In the app_process program, he will manually register the Android JNI and can use the Android API well. Therefore, he starts a JAVA program by running the app_process program, is a perfect method. App_process is a C program whose source code is in frameworks \ base \ cmds \ app_process.
For details about how to use it, see Android command am and shell script frameworks \ base \ cmds \ am and frameworks \ base \ cmds \ pm
The am Script file is as follows: www.2cto.com
# Script to start "am" on the device, which has a very rudimentary
# Shell.
#
Base =/system
Export CLASSPATH = $ base/framework/am. jar
Exec app_process $ base/bin com. android. commands. am. Am "$ @"
The pm script file is as follows:
# Script to start "pm" on the device, which has a very rudimentary
# Shell.
#
Base =/system
Export CLASSPATH = $ base/framework/pm. jar
Exec app_process $ base/bin com. android. commands. pm. Pm "$ @"
CLASSPATH specifies the location of your program, com. android. commands. pm. pm indicates that the program entry is com. android. commands. pm. pm, that is, the class where the main () function is located. "$ @" refers to the parameter passed to the main () function, but here "$ @" is itself a parameter passed by shell.
Note that the files in CLASSPATH must be in the dalvik file format. For the conversion, see Basic Dalvik VM call. Of course, the files in CLASSPATH can be apk files, only your apk should have at least one class with the main () entry function.
Author: hudashi