你好,游客 登录 注册 搜索
背景:
阅读新闻

Android框架简介

JAVA环境(中)

[日期:2011-10-10] 来源:Linux社区  作者:hongchunhua [字体:大 中 小]

在我平时工作中主要是进行linux网络子系统的模块开发、linux应用程序(C/C++)开发。在学习和从事驱动模块开发的过程中,如果你对linux系统本身,包括应用程序开发都不了解,那么读内核代码就如同天书,毫无意义,所以我分析框架也是从基本系统api开始的,当然也不会太多涉及到应用程序开发。

好,开始这节主要是讲一个简单的adnroid应用程序,从应用程序出发,到框架代码。

分析的应用程序我们也奉行拿来主义:froyo/development/samples/HelloActivity

./
|-- Android.mk
|-- AndroidManifest.xml
|-- res
|-- src
`-- tests

其他的就多说了,看代码

  1. /* 
  2.  * Copyright (C) 2007 The Android Open Source Project 
  3.  * 
  4.  * Licensed under the Apache License, Version 2.0 (the "License"); 
  5.  * you may not use this file except in compliance with the License. 
  6.  * You may obtain a copy of the License at 
  7.  * 
  8.  *      http://www.apache.org/licenses/LICENSE-2.0 
  9.  * 
  10.  * Unless required by applicable law or agreed to in writing, software 
  11.  * distributed under the License is distributed on an "AS IS" BASIS, 
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  13.  * See the License for the specific language governing permissions and 
  14.  * limitations under the License. 
  15.  */  
  16. package com.example.android.helloactivity;  
  17. import android.app.Activity;  
  18. import android.os.Bundle;  
  19. /** 
  20.  * A minimal "Hello, World!" application. 
  21.  */  
  22. public class HelloActivity extends Activity {  
  23.     public HelloActivity() {  
  24.     }  
  25.     /** 
  26.      * Called with the activity is first created. 
  27.      */  
  28.     @Override  
  29.     public void onCreate(Bundle savedInstanceState) {  
  30.         super.onCreate(savedInstanceState);  
  31.         // Set the layout for this activity.  You can find it   
  32.         // in res/layout/hello_activity.xml   
  33.         setContentView(R.layout.hello_activity);  
  34.     }  
  35. }   

每一个写过android程序的人都应该是从这个代码起步的吧?那好,那么我们研究android框架也从这里启航。

首先是

记住,我们这里不是讲JAVA,我们要讲的是android.app.Activity,回顾上节的内容,android的JAVA框架代码放在froyo/frameworks/base/,
其中Activity的代码放在框架代码的core/java/android/app/Activity.java,大概看一下

  1. public class Activity extends ContextThemeWrapper  
  2.         implements LayoutInflater.Factory,  
  3.         Window.Callback, KeyEvent.Callback,  
  4.         OnCreateContextMenuListener, ComponentCallbacks {  
  5.     private static final String TAG = "Activity";  
  6.     /** Standard activity result: operation canceled. */  
  7.     public static final int RESULT_CANCELED    = 0;  
  8.     /** Standard activity result: operation succeeded. */  
  9.     public static final int RESULT_OK           = -1;  
  10.     /** Start of user-defined activity results. */  
  11.     public static final int RESULT_FIRST_USER   = 1;  
  12.     private static long sInstanceCount = 0;  

同样的Bundle的代码core/java/android/os/Bundle.java

  1. public final class Bundle implements Parcelable, Cloneable {  
  2.     private static final String LOG_TAG = "Bundle";  
  3.     public static final Bundle EMPTY;  

呵呵,其实写多应用程序,然后看看这些代码,会有更加豁然开朗的感觉,所以列出以上目录给大家参考,所有的java框架代码都在那个目录下,到这里今天要讨论的第一个问题就到这里了。

我所在的公司是网络设备供应商,其实和android本身不搭边,android只是平时的爱好而已,所以很多地方如果写错了敬请原谅,当然也计划去做做android系统开发,例如驱动或者是框架开发,这是后话。

linux
【内容导航】
第1页:JAVA环境(上) 第2页:JAVA环境(中)
第3页:JAVA环境(下)
相关资讯       Dalvik  Android开发 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款