How to start a JAVA program in Android

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.