Get started with Android APP development

Source: Internet
Author: User
Tags android sdk manager

Get started with Android APP development

This article describes how to get started with Android APP development, including SDK download, Development Environment setup, code writing, and APP packaging. It is a very simple Android APP development getting started tutorial, for more information, see

I have worked on a mobile App project. The front-end and android or ios programmers can work together to develop the entire project. There is basically no problem in working with ios programs during the development process, there are many problems with android sub-devices and rom, which also gives me an interest in learning android and ios program development. So I couldn't sleep at all in the early morning and wrote the first android program HelloAndroid. I took the po and shared it with other android Developers who wanted to learn about Android development, you can understand the development basics.

I. Preparations

Take my own development environment as an example to download and install the JDK and Android SDK. If you do not have a ready-made IDE, you can directly download the complete SDK package, which contains Eclipse, if you have an ide, you can scroll down to select use an existing ide and install the SDK. If your SDK cannot find the JDK directory during installation, you can add the JAVA_HOME variable to the system environment variable. The path is your JDK directory. My IDE is IntelliJ IDEA. After all the variables are installed, configure the IDE to add SDK support.

First, enable the Android SDK Manager to check all uninstalled Android 4.0 and later versions. Based on your actual situation, if you only plan to use your mobile phone for testing, package the SDK of the same version as your sub-system, and the download takes a long time.

Open the IDE to create a New Project. IDEA is intelligent. If you have installed the SDK, the Android Application Module will appear in the New Project. After you select it, the Project SDK on the right is blank. Click the New button, find the SDK directory, and the drop-down list will list the sdks of installed versions. Select the desired version. If this is the first time you set the SDK, IDE will remind you to set JDK first, find the JDK directory as prompted.

After the project name is filled in, select USB Device next, and then complete the project construction. The IDE will automatically generate the files and directories required for the basic project.

Ii. Coding

After preparation, we can finally start writing our hello android. before writing code, we should first understand several files:

Res/layout/main. xml the main form layout file of the App. Your application is defined here. There are two modes: Design and Text.

Res/values/strings. xml can be understood as an i18n file, which is used to store various strings called by the program.

Src/com/example/helloandroid/MyActivity. java: This is our main program class. add all the functions to be implemented in this file.

First, add a textview with the id hellotextView and a button with the id hellobutton to the application. The mail. xml Code is as follows:

Copy the Code as follows:

Android: orientation = "vertical"

Android: layout_width = "fill_parent"

Android: layout_height = "fill_parent"

>

Android: layout_width = "fill_parent"

Android: layout_height = "180dp"

Android: text = "@ string/default_message"

Android: id = "@ + id/hellotextView" android: textColor = "#00ff00" android: gravity = "center"/>

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: text = "@ string/button_send"

Android: id = "@ + id/hellobutton" android: layout_gravity = "center"/>

The strings used by codes and controls are defined as follows:

Copy the Code as follows:

Helloandroid by hiwanz

Say something

Click button below!

You just clicked on the Button!

In the main program, after the button is clicked, the text displayed in textview is changed and the Toast prompt is displayed. The Code is as follows:

Copy the Code as follows:

Package com. example. helloandroid;

Import android. app. Activity;

Import android. OS. Bundle;

Import android. view. View;

Import android. widget. Button;

Import android. widget. TextView;

Import android. widget. Toast;

Public class MyActivity extends Activity {

/**

* Called when the activity is first created.

*/

@ Override

Public void onCreate (Bundle savedInstanceState ){

Super. onCreate (savedInstanceState );

SetContentView (R. layout. main );

// Get the button instance

Button hellobtn = (Button) findViewById (R. id. hellobutton );

// Set listener button click event

Hellobtn. setOnClickListener (new View. OnClickListener (){

@ Override

Public void onClick (View v ){

// Obtain the textview instance

TextView hellotv = (TextView) findViewById (R. id. hellotextView );

// The Toast prompt button is clicked.

Toast. makeText (MyActivity. this, "Clicked", Toast. LENGTH_SHORT). show ();

// Read the interact_message defined in strings. xml and write it to textview.

Hellotv. setText (R. string. interact_message );

}

});

}

}

After the code is written, the computer uses the USB data cable to connect to the mobile phone. Enable USB debugging in the developer option in the mobile phone system settings. Directly click Run in the IDE to view the running effect on the mobile phone.

Application Packaging

After the application development is complete, it will be packaged and released. Select Generate Signed APK under the IDE Build menu to package the application.

In the displayed Wizard dialog box, you need to specify the signature Key. If no Key exists at the beginning, you can click Create New to Create a New Key for signature. Fill in the required fields of the signature and generate the Key file.

Use the generated Key to sign the application package

After compilation, We will generate our helloandroid.apk application package under the Designation APK pathwe just set. We should not have to say how to install the application. Our first Android App was born like this.

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.