主要参考
http://code.google.com/p/androidbmi/wiki/DiveIntoAndroid
这个教程是一个比较好的教程,但是天下没有人人满意的东西。
主要而言,对某些读者,该教程有两个小小的不足,1是繁体字,2是作者照顾了很多刚入门的程序员,写的太细致了,比如还要抽空讲一讲java,xml的一些语法。
本文的特点就是,1普通话,2面向有java,xml经验的程序员。主要是从一个小例子阐述一下OPhone/Android的一些重要概念。
本文的目标是除去搭建环境外的一个5分钟快速入门。并提供一个简单的程序代码可以用来修改验证一些OPhone/Android入门时的想法,并对OPhone/Android的重要概念有一个大致的了解。
本文提供的code的测试搭建环境为OPhone。
1 背景
Android是什么?
Android 是Google开发的基于Linux平台的开源手机操作系统。
OPhone是什么?
OPhone是中国移动OMS系统下定制的手机。OPhone上的程序和Android是兼容的。
Emulator是什么?
方便程序员开发其他设备上的程序,而对其他设备做的一个软件模拟器。开发的程序可以在模拟器上部署,执行,调试。
2 安装开发环境
Android:
http://code.google.com/p/androidbmi/wiki/InstallAndroid
JDK5+
Eclipse3.3+
ADT
Android SDK(包含Emulator)
OPhone:
http://www.ophonesdn.com/documentation/ophone/gettingstarted/installing_sdk.html
JDK5+
Eclipse3.4.2
ADT
WDT
OPhoneSDK(包含Emulator)
注意安装的最后步骤在Eclipse中设置Android SDK Location。
3 创建简单的OPhone程序
在Eclipse中创建一个Android project。
里面有如下选项需要填写:
Project Name:项目名称。
Package name:命名空间。
Activity name:先理解为程序的入口类,以后解释。
Application name:程序名称。
记得加入android.jar和oms.jar。
4 OPhone目录结构及意义
创建好的OPhone项目有如下基本结构。
src:java code。
res:OPhone的资源。
res\drawable:图片。
res\layout:布局描述。
res\values:字符串定义。
AndroidManifest.xml:描述该OPhone程序。
5 OPhone关键概念。
部署相关:
虽然我们是用java开发的,但是结果并不是常见的jar,而是dex,或者apk。
过程是这样的,我们编写java,编译成class,优化处理成dex(相对来说mobile还是一个受限环境),和资源一起打包成apk文件。部署后由Dalvik VM执行。
一个Ophone的应用是多个Activity的集合。可以在AndroidManifest.xml中指定该Ophone App的入口Activity.
一个Activity是一个和用户的基本交互流,有其自身的生命周期。Activity之间可以通过Intent传递信息。
关于Activity的生命周期可以参考
http://code.google.com/p/androidbmi/wiki/LifeCycle
一个Activity的实现采用的是MVC,其中code部分负责MC,res\layout中的xml负责View。
App中使用的字符串都可以放在res\values下xml中统一维护,方便系统的维护,管理。
项目自动生成一个R.java来管理资源相关的引用。开发者不需要手动修改该文件。
6 小例子截图。
这个例子的功能是用户输入名字,程序对该用户说hello。
7 关键代码解释
HelloOPhone定义了入口Activity。
Echo定义了打招呼的Activity。
看看HelloOPhone的View部分是怎么定义的,xml的自描述性真好,都不用解释。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/input_msg" />
<EditText android:id="@+id/name" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="" />
<Button android:id="@+id/ok" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/ok" />
</LinearLayout>
看看一个Activity是怎样和这个xml联系起来的。通过自动生成的R.java中的定义。注意定义的xml文件名改变R会自动刷新。
setContentView(R.layout.input);
再看看一个Activity如何通过xml中的id找到该View.
b_ok = (Button) findViewById(R.id.ok);
再看看Activity怎么通过Intent启动另一个Echo Activity,并且给那个Activity传递信息。
Intent intent = new Intent();
intent.setClass(HelloOPhone.this, Echo.class);
Bundle bundle = new Bundle();
bundle.putString("name", name);
intent.putExtras(bundle);
startActivity(intent);
再看看Echo如何接收传递来的信息。
Bundle bunde = this.getIntent().getExtras();
String name = bunde.getString("name");
最后简单的看看AndroidManifest.xml如何描述该app。
其中指明了命名空间,程序的图像等等。
同时指出该app由2个Activity组成,并设置了HelloOPhone为入口Activity。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="allen.oms" android:versionCode="1" android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloOPhone" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Echo" android:label="@string/app_name" />
</application>
</manifest>

- 大小: 28.4 KB
分享到:
相关推荐
而Ophone则是由中国移动推出的基于Android定制的操作系统,旨在提供更好的本地化体验和服务。 #### 标题解析:“Ophone / Android 系统属性列表” 此标题明确指出本文档将提供一系列与Ophone和Android相关的系统...
在Android和Ophone开发领域,源码是学习与探索系统工作原理、优化应用性能以及创新技术实践的关键资源。这份"Android/Ophone开发完全讲义源码"为开发者提供了丰富的学习材料,涵盖了Android和Ophone平台的基础到高级...
《Android/Ophone开发讲义源码解析》 在移动应用开发领域,Android系统以其开源、灵活的特点,成为了全球最受欢迎的智能手机操作系统之一。Ophone则是中国移动基于Android系统进行深度定制的一个版本,它在中国市场...
本书是国内第一本同时介绍Android和OPhone的经典著作,国内著名Android社区eoeandroid极力推荐。全书分为五大部分,共二十五章,主要内容包括:Android应用程序架构,移动存储解决方案,Android服务,资源、国际化与...
《Android/OPhone开发完全讲义》是一本深入探讨Android和OPhone开发的综合性教材,主要针对想要在Android平台上进行应用程序开发的工程师和技术爱好者。这本书不仅涵盖了Android的基础知识,还涉及了OPhone这一中国...