android app(3)-Hello world程序分析
来源:互联网 发布:捕鱼游戏机核心算法 编辑:程序博客网 时间:2024/05/19 03:17
上一节中使用向导生成了第一个程序"Hello world!"。
这是一个JAVA程序,它运行在Dalvik虚拟机中,不同其它的虚拟机,每个Android应用程序都运行在单独的Dalvik虚拟机中。Dalvik运行的是.dex文件,并非JVM的.class文件。
Hello world程序生成后,它的入口在MainActivity.java
package com.myexample.test0;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}}
MainActivity是程序创建的一个活动,它从Activetity继承。
Activetity是Android app中用户交互界面的组件,它是Android app界面开发中最重要的组件之一,类似于windows开发中的"窗体"。
java.lang.Object ↳android.content.Context ↳android.content.ContextWrapper ↳android.view.ContextThemeWrapper ↳android.app.Activity
Activetity的继承类一般会重载两个方法:
(1)onCreate(Bundle)
它在Activetity创建时调用,在这里做UI界面的初始化工作。setContentView(R.layout.activity_main)的作用是设置UI界面为资源activity_main。
(2)onPause()
它在Activetity离开时调用。
一个Activetity可以调用另一个Activetity:使用父类Contex的startActivity()方法,但它必须在AndroidManifest.xml中声明:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myexample.test0" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" ><span style="color:#ff0000;"> <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity></span> </application></manifest>
每个资源都会生成一个id,保存R.java中,R.java是编译时自动生成的一个文件,如果要在程序中使用一个资源,例如:
setContentView(R.layout.activity_main);
资源文件在项目的res文件夹中:
drawable-xxxhdpi分别是高,低、中、超高、巨高分辨率的图片文件。
activity_main.xml是activity_main活动的界面布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${relativePackage}.${activityClass}" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /></RelativeLayout>
TextView是一个文本框,它显示资源hello_word中定义的字体串。
strings.xml是字符串常量的定义:
<?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">Test0</string> <string name="hello_world">Hello world!</string></resources>如果要在xml中使用一个字符串,activity_main.xml有一个示例:
android:text="@string/hello_world"
styles.xml资源:
<resources> <!-- Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> <style name="AppBaseTheme" parent="Theme.AppCompat.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style></resources>
另外还一些依赖库,这就是一个Android App的所有文件。
当生成一个app时,它生成的是一个安装文件,后缀是apk。在IDE启动调试或运行时,它会使用adb命令安装到目标机器。
- android app(3)-Hello world程序分析
- Hello, World! from Android APP
- Hello World程序运行分析
- 学习笔记之----透彻分析android程序之-------hello world
- Android APP--Hello World编写
- 使用二进制工具分析Hello World程序
- wechat-小程序(hello world)分析
- 2 逆向分析hello world!程序
- 关于android hello world程序的编写
- 第一个Android程序"Hello,World"
- android下第一个程序,Hello World
- 第一个Android程序 Hello World!
- 第一个Android程序--Hello World
- android第一个程序hello world
- 2.第一个Android程序“Hello,World!”
- Django Hello World app
- android app小白试水1-app的创建和hello,world
- 第3章、第一个“Hello,world!”之Android App(从零开始学Android)
- openSUS开启root账户ssh远程登录方法汇总
- C语言中 *号的用途
- 学习笔记 Hadoop是什么?
- 安卓中显示单位:px和dip以及sp的讲解
- Unity3D DestroyImmediate Destroy
- android app(3)-Hello world程序分析
- 计算几何
- wifidog数据流图
- UVa 1593 Alignment of Code
- 制作Apple安装U盘
- 【Codeforces】 487A Fight the Monster
- 挂载zookeeper到文件系统 (mount zookeeper)
- 软件工程师应该知道的9件事
- 实用与时尚兼备 DNNO多诺移动电源体验