Developing standalone Android Java applications

Source: Internet
Author: User

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

 

 

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.