现在的位置: 首页 > 综合 > 正文

精通Android4学习笔记-设置开发环境

2013年11月07日 ⁄ 综合 ⁄ 共 2125字 ⁄ 字号 评论关闭

  之前看过一些资料,做过几个app,主要是通过视频来学习的,效果还不错。

  正好公司有个学习小组,我有了开发apk的任务,再从头学习一遍,这次有了学习小组的规定教材-精通Android4.

  温故而知新

1.avd的设置

snapshot可以提高AVD启动的速度 ;

设置target的api高版本,可以兼容更多基于低版本sdk开发的apk;

但是高版本的缺陷是内存等等资源占用比较多,因为一般来说屏幕比较大。

2.android应用程序框架的基本组件

view

activity

intent

content provider

service

fragment

AndroidManifest.xml

 

3.avd的进一步知识

可以在命令行创建avd

创建的avd,缺省情况一般放在用户目录的.android\AVD文件夹里面;

也可以指定avd的文件夹;

#得到target的列表

android list target

id: 2 or "Google Inc.:Google APIs:3"
     Name: Google APIs
     Type: Add-On
     Vendor: Google Inc.
     Revision: 3
     Description: Android + Google APIs
     Based on Android 1.5 (API level 3)
     Libraries:
      * com.google.android.maps (maps.jar)
          API for Google Maps
     Skins: QVGA-P, HVGA-L, HVGA (default), QVGA-L, HVGA-P
     ABIs : armeabi

#创建一个avd

android create avd -n CupcakeMaps -t 3 -c 16M -p c:\avd\CupcakeMaps\

就算这样做,在%home%/.android/avd下面还有一个文件CupcakeMaps.ini,里面存放了该avd的信息

avd.ini.encoding=ISO-8859-1
target=android-4
path=C:\Documents and Settings\jian.zhang\.android\avd\CupcakeMaps.avd
path.rel=avd\CupcakeMaps.avd
 

4.android 应用程序的源码结构

AndroidManifest.xml

The Android application descriptor file. This file defines the
activities, content providers, services, and intent receivers of
the application. You can also use this file to declaratively
define permissions required by the application, as well as
grant specific permissions to other applications using the
services of the application. Moreover, the file can contain
instrumentation detail that you can use to test the application
or another application.

 

src

assets

res

drawable

animator

layout

menu

values

xml

raw

5.了解应用程序生命周期

   由系统根据用户需求及可用资源等进行严格管理。

  尽管系统是最终的决定者,但它会遵从一些既定的和逻辑上的原则。

 

Listing 2–1. Life-Cycle Methods of an Activity
protected void onCreate(Bundle savedInstanceState);
protected void onStart();
protected void onRestart();
protected void onResume();
protected void onPause();
protected void onStop();
protected void onDestroy();

 记住:如果实现了这些生命周期方法,一定要确保也调用了超类的相应方法。

最常用的方法是onCreate,onResume和onPause

onPause()里面,你可能希望保存关键的数据,这个方法是系统结束应用程序前调用的最后一个安全的方法。无法保证onStop和onDestroy会被调用,所以不要依赖这些方法来实现关键逻辑。

Activity中可以获取应用程序上下文。

6.简单调试

LogCat

显示android.util.Log,异常,System.out.println等发出的日志信息。

尽量使用Log类,因为这个类的方法可以区分信息的级别,以便于后面对信息的过滤处理。

这些日志信息的级别有info,warning,error等等,可以调用Log的不同方法来实现信息的分级。

不要在准备生产部署的应用上留下冗长的调用,因为日志记录会消耗内存和占用CPU资源。

 

 

抱歉!评论已关闭.