[Getting Started] Android Application Framework

Source: Internet
Author: User
Take helloactivity Program For example, we will briefly introduce the framework of Android applications. It is hoped that the reader can write an andorid Application Based on helloactivity.

Helloactivity Project Source code In the android directory development/samples/helloactivity, Code The structure is as follows:
Development/samples/helloactivity/
| -- Android. mk
| -- Androidmanifest. xml
| -- Res
| -- Layout
| '-- Hello_activity.xml
| '-- Values
| '-- Strings. xml
| -- SRC
'-- Com
'-- Example
'-- Android
'-- Helloactivity
'-- Helloactivity. Java

Tests is an independent project, which can be ignored for the moment. Other parts are considered as an Android Application project. The main components of this project are as follows:
Android. mk
Is the "makefile" of the entire project. Its content is as follows:
Local_path: = $ (call my-DIR)
Include $ (clear_vars)
Local_module_tags: = Samples
# Only compile source Java files in this APK.
Local_src_files: = $ (call all-Java-files-under, Src)
Local_package_name: =Helloactivity
Local_sdk_version: = Current
Include $ (build_package)
# Use the following include to make our test APK.
Include $ (call all-makefiles-under, $ (local_path ))
Local_package_name indicates the package name. This file is the name of the final generated package (*. APK). Note that the package name is irrelevant to the name of the application directory. Helloactivity .

Androidmanifest. xml

Project description file

<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android =" Http://schemas.android.com/apk/res/android "
Package ="Com. example. Android. helloactivity">
<Application Android: Label ="Hello, activity!">
<Activity Android: Name ="Helloactivity">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
</Application>
</Manifest>
In the project description file, Package The name must be the same as that in the Java file, Activity The name must be the same as the name of the Java class in the Java file, and the file name of the Java file must also be the same as the name of the class.
And that Android: Label The name is both the name of the application in the menu and the title after the application is started.

Helloactivity. Java
This is a Java class file. The path of this file indicates the position in the structure of the Java package of andorid. The usage of this package is com. example. Android. helloactivity.

PackageCom. example. Android. helloactivity;
Import Android. App. activity;
Import Android. OS. Bundle;
Public classHelloactivityExtends activity {
Public helloactivity (){
}
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. hello_activity );
}
}

The androidmanifest. xml and *. Java names must match (helloactivity. Java and helloactivity here). Otherwise, the Java class cannot be found.

After the program is compiled, the APK package will be generated and placed in system/app. In addition to the interface startup, you can also start the qemu simulator in the following way:
Am start-N com. example. Android. helloactivity/COM. example. Android. helloactivity. helloactivity

In fact, the startup method is related to the name in the project description file and the class name.

Notes:
1. The name of the application folder has no actual effect.
2. The local_package_name of Android. mk determines the name of the APK package;
3. androidmanifest. xml must contain the package name and Activity Class Name and correspond to the Java file;
4. The name of application Android: Label in androidmanifest. XML is both the name of the application on the interface and the title after startup.

This article is transferred fromWww.35java.com

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.