在我平时工作中主要是进行linux网络子系统的模块开发、linux应用程序(C/C++)开发。在学习和从事驱动模块开发的过程中,如果你对linux系统本身,包括应用程序开发都不了解,那么读内核代码就如同天书,毫无意义,所以我分析框架也是从基本系统api开始的,当然也不会太多涉及到应用程序开发。
好,开始这节主要是讲一个简单的adnroid应用程序,从应用程序出发,到框架代码。
分析的应用程序我们也奉行拿来主义:froyo/development/samples/HelloActivity
./
|-- Android.mk
|-- AndroidManifest.xml
|-- res
|-- src
`-- tests
其他的就多说了,看代码
- /*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package com.example.android.helloactivity;
- import android.app.Activity;
- import android.os.Bundle;
- /**
- * A minimal "Hello, World!" application.
- */
- public class HelloActivity extends Activity {
- public HelloActivity() {
- }
- /**
- * Called with the activity is first created.
- */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // Set the layout for this activity. You can find it
- // in res/layout/hello_activity.xml
- setContentView(R.layout.hello_activity);
- }
- }
每一个写过android程序的人都应该是从这个代码起步的吧?那好,那么我们研究android框架也从这里启航。
首先是
- import android.app.Activity;
- import android.os.Bundle;
记住,我们这里不是讲JAVA,我们要讲的是android.app.Activity,回顾上节的内容,android的JAVA框架代码放在froyo/frameworks/base/,
其中Activity的代码放在框架代码的core/java/android/app/Activity.java,大概看一下
- public class Activity extends ContextThemeWrapper
- implements LayoutInflater.Factory,
- Window.Callback, KeyEvent.Callback,
- OnCreateContextMenuListener, ComponentCallbacks {
- private static final String TAG = "Activity";
- /** Standard activity result: operation canceled. */
- public static final int RESULT_CANCELED = 0;
- /** Standard activity result: operation succeeded. */
- public static final int RESULT_OK = -1;
- /** Start of user-defined activity results. */
- public static final int RESULT_FIRST_USER = 1;
- private static long sInstanceCount = 0;
同样的Bundle的代码core/java/android/os/Bundle.java
- public final class Bundle implements Parcelable, Cloneable {
- private static final String LOG_TAG = "Bundle";
- public static final Bundle EMPTY;
呵呵,其实写多应用程序,然后看看这些代码,会有更加豁然开朗的感觉,所以列出以上目录给大家参考,所有的java框架代码都在那个目录下,到这里今天要讨论的第一个问题就到这里了。
我所在的公司是网络设备供应商,其实和android本身不搭边,android只是平时的爱好而已,所以很多地方如果写错了敬请原谅,当然也计划去做做android系统开发,例如驱动或者是框架开发,这是后话。
