为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

Android手机开发网整理资料

2011-06-28 50页 doc 173KB 9阅读

用户头像

is_722498

暂无简介

举报
Android手机开发网整理资料Android 多媒体框架 OpenCore(PacketVideo)介绍 OpenCore的另外一个常用的称呼是PacketVideo,它是Android的多媒体核心。PacketVideo是一家公司的名称,OpenCore是这套多媒体框架的软件层的名称。在Android的开发者层次看,二者的含义基本相同。对比Android的其它程序库,OpenCore的代码非常庞大,它是一个基于C++的实现,定义了全功能的操作系统移植层,各种基本的功能均被封装成类的形式,各层次之间的接口多使用继承等方式。OpenCore是一个多媒体的框架...
Android手机开发网整理资料
Android 多媒体框架 OpenCore(PacketVideo)介绍 OpenCore的另外一个常用的称呼是PacketVideo,它是Android的多媒体核心。PacketVideo是一家公司的名称,OpenCore是这套多媒体框架的软件层的名称。在Android的开发者层次看,二者的含义基本相同。对比Android的其它程序库,OpenCore的代码非常庞大,它是一个基于C++的实现,定义了全功能的操作系统移植层,各种基本的功能均被封装成类的形式,各层次之间的接口多使用继承等方式。OpenCore是一个多媒体的框架,从宏观上来看,它主要包含了两大方面的内容:   * PVPlayer:提供媒体播放器的功能,完成各种音频(Audio)、视频(Video)流的回放(Playback)功能   * PVAuthor:提供媒体流记录的功能,完成各种音频(Audio)、视频(Video)流的以及静态图像捕获功能   PVPlayer和PVAuthor以SDK的形式提供给开发者,可以在这个SDK之上构建多种应用程序和服务。比如在移动终端中常常使用的多媒体应用程序,例如媒体播放器、照相机、录像机、录音机等等。   为了更好的组织整体的架构,OpenCore在软件层次在宏观上分成几个层次:   * OSCL:Operating System Compatibility Library (操作系统兼容库),包含了一些操作系统底层的操作,为了更好地在不同操作系统移植。包含了基本数据类型、配置、字符串工具、IO、错误处理、线程等内容,类似一个基础的C++库。   * PVMF:PacketVideo Multimedia Framework(PV多媒体框架),在框架内实现一个文件解析(parser)和组成(composer)、编解码的NODE,也可以继承其通用的接口,在用户层实现一些NODE。   * PVPlayer Engine:PVPlayer引擎。   * PVAuthor Engine:PVAuthor引擎。   事实上,OpenCore中包含的内容非常多:从播放的角度,PVPlayer的输入(Source)是文件或者网络媒体流,输出(Sink)是音频视频的输出设备,其基本功能包含了媒体流控制、文件解析、音频视频流的解码(Decode)等方面的内容。除了从文件中播放媒体文件之外,还包含了与网络相关的RTSP流(Real Time Stream Protocol,实时流协议)。在媒体流记录的方面,PVAuthor的输入(Source)是照相机、麦克风等设备,输出(Sink)是各种文件,包含了流的同步、音频视频流的编码(Encode)以及文件的写入等功能。   在使用OpenCore的SDK的时候,有可能需要在应用程序层实现一个适配器(Adaptor),然后在适配器之上实现具体的功能,对于PVMF的NODE也可以基于通用的接口,在上层实现,以插件的形式使用。 第二部分 OpenCore的代码结构   2.1 代码结构   以开源Android的代码为例,OpenCore的代码在以下目录中:external/opencore/。这个目录是OpenCore的根目录,其中包含的子目录如下所示:   * android:这里面是一个上层的库,它基于PVPlayer和PVAuthor的SDK实现了一个为Android使用的Player和Author。   * baselibs:包含数据结构和线程安全等内容的底层库   * codecs_v2:这是一个内容较多的库,主要包含编解码的实现,以及一个OpenMAX的实现   * engines:包含PVPlayer和PVAuthor引擎的实现   * extern_libs_v2:包含了khronos的OpenMAX的头文件   * fileformats:文件格式的解析(parser)工具   * nodes:提供一些PVMF的NODE,主要是编解码和文件解析方面的。   * oscl:操作系统兼容库   * pvmi: 输入输出控制的抽象接口   * protocols:主要是与网络相关的RTSP、RTP、HTTP等协议的相关内容   * tools_v2:编译工具以及一些可注册的模块。   在external/opencore/目录中还有2个文件,如下所示:   * Android.mk:全局的编译文件   * pvplayer.conf:配置文件   在external/opencore/的各个子文件夹中包含了众多的Android.mk文件,它们之间还存在着“递归”的关系。例如根目录下的Android.mk,就包含了如下的内容片断:   include $(PV_TOP)/engines/player/test/Android.mk   include $(PV_TOP)/engines/author/test/Android.mk   include $(PV_TOP)/engines/2way/test/Android.mk   这表示了要引用若干文件夹下面的Android.mk文件。external/opencore/的各个Android.mk文件可以按照排列组合进行使用,将几个Android.mk内容合并在一个库当中。   2.2 编译结构   1.库的层次关系:在Android的开源版本中编译出来的内容,OpenCore编译出来的各个库如下所示:   * libopencorecommon.so:OpenCore底层的公共库   * libopencoredownloadreg.so :下载注册库   * libopencoredownload.so:下载功能实现库   * libopencoremp4reg.so:MP4注册库   * libopencoremp4.so:MP4功能实现库   * libopencorenet_support.so:网络支持库 * libopencoreplayer.so:OpenCore的Player库   * libopencoreauthor.so:OpenCore的Author库   * libopencorertspreg.so:RTSP注册库   * libopencorertsp.so:RTSP功能实现库   OpenCore的各个库之间具有如下的关系:   libopencorecommon.so是所有的库的依赖库,提供了公共的功能;   libopencoreplayer.so和libopencoreauthor.so是两个并立的库,分别用于回放和记录,而且这两个库是OpenCore对外的接口库;   libopencorenet_support.so提供网络支持的功能;   一些功能以插件(Plug-In)的方式放入Player中使用,每个功能使用两个库,一个实现具体功能,一个用于注册。   2.libopencorecommon.so库的结构   libopencorecommon.so是整个OpenCore的核心库,它的编译控制的文件的路径为pvcommon/Android.mk,这个文件使用递归的方式寻找子文件:   include $(BUILD_SHARED_LIBRARY)   include $(PV_TOP)//oscl/oscl/osclbase/Android.mk   include $(PV_TOP)//oscl/oscl/osclerror/Android.mk   include $(PV_TOP)//oscl/oscl/osclmemory/Android.mk   include $(PV_TOP)//oscl/oscl/osclutil/Android.mk   include $(PV_TOP)//oscl/pvlogger/Android.mk   include $(PV_TOP)//oscl/oscl/osclproc/Android.mk   include $(PV_TOP)//oscl/oscl/osclio/Android.mk   include $(PV_TOP)//oscl/oscl/osclregcli/Android.mk   include $(PV_TOP)//oscl/oscl/osclregserv/Android.mk   include $(PV_TOP)//oscl/unit_test/Android.mk   include $(PV_TOP)//oscl/oscl/oscllib/Android.mk   include $(PV_TOP)//pvmi/pvmf/Android.mk   include $(PV_TOP)//baselibs/pv_mime_utils/Android.mk   include $(PV_TOP)//nodes/pvfileoutputnode/Android.mk   include $(PV_TOP)//baselibs/media_data_structures/Android.mk   include $(PV_TOP)//baselibs/threadsafe_callback_ao/Android.mk   include $(PV_TOP)//codecs_v2/utilities/colorconvert/Android.mk   include $(PV_TOP)//codecs_v2/audio/gsm_amr/amr_nb/common/Android.mk   include $(PV_TOP)//codecs_v2/video/avc_h264/common/Android.mk 这些被包含的Android.mk文件真正指定需要编译的文件,这些文件在Android.mk的目录及其子目录中。事实上,在libopencorecommon.so库中包含了以下内容:   * OSCL的所有内容   * Pvmf框架部分的内容(pvmi/pvmf/Android.mk)   * 基础库中的一些内容(baselibs)   * 编解码的一些内容   * 文件输出的node(nodes/pvfileoutputnode/Android.mk)   从库的结构中可以看出,最终生成库的结构与OpenCore的层次关系并非完全重合。libopencorecommon.so库中就包含了底层的OSCL的内容、PVMF的框架以及Node和编解码的工具。   3.libopencoreplayer.so库的结构   libopencoreplayer.so是用于播放的功能库,它的编译控制的文件的路径为pvplayer/Android.mk,它包含了以下的内容:   include $(BUILD_SHARED_LIBRARY)   include $(PV_TOP)//engines/player/Android.mk   include $(PV_TOP)//codecs_v2/audio/aac/dec/util/getactualaacconfig/Android.mk   include $(PV_TOP)//codecs_v2/video/avc_h264/dec/Android.mk   include $(PV_TOP)//codecs_v2/audio/aac/dec/Android.mk   include $(PV_TOP)//codecs_v2/audio/gsm_amr/amr_nb/dec/Android.mk   include $(PV_TOP)//codecs_v2/audio/gsm_amr/amr_wb/dec/Android.mk   include $(PV_TOP)//codecs_v2/audio/gsm_amr/common/dec/Android.mk   include $(PV_TOP)//codecs_v2/audio/mp3/dec/Android.mk   include $(PV_TOP)//codecs_v2/utilities/m4v_config_parser/Android.mk   include $(PV_TOP)//codecs_v2/utilities/pv_video_config_parser/Android.mk   include $(PV_TOP)//codecs_v2/omx/omx_common/Android.mk   include $(PV_TOP)//codecs_v2/omx/omx_queue/Android.mk   include $(PV_TOP)//codecs_v2/omx/omx_h264/Android.mk   include $(PV_TOP)//codecs_v2/omx/omx_aac/Android.mk   include $(PV_TOP)//codecs_v2/omx/omx_amr/Android.mk   include $(PV_TOP)//codecs_v2/omx/omx_mp3/Android.mk   include $(PV_TOP)//codecs_v2/omx/factories/omx_m4v_factory/Android.mk   include $(PV_TOP)//codecs_v2/omx/omx_proxy/Android.mk  include $(PV_TOP)//nodes/common/Android.mk   include $(PV_TOP)//pvmi/content_policy_manager/Android.mk   include $(PV_TOP)//pvmi/content_policy_manager/plugins/oma1/passthru/Android.mk   include $(PV_TOP)//pvmi/content_policy_manager/plugins/common/Android.mk   include $(PV_TOP)//pvmi/media_io/pvmiofileoutput/Android.mk   include $(PV_TOP)//fileformats/common/parser/Android.mk   include $(PV_TOP)//fileformats/id3parcom/Android.mk   include $(PV_TOP)//fileformats/rawgsmamr/parser/Android.mk   include $(PV_TOP)//fileformats/mp3/parser/Android.mk   include $(PV_TOP)//fileformats/mp4/parser/Android.mk   include $(PV_TOP)//fileformats/rawaac/parser/Android.mk   include $(PV_TOP)//fileformats/wav/parser/Android.mk   include $(PV_TOP)//nodes/pvaacffparsernode/Android.mk   include $(PV_TOP)//nodes/pvmp3ffparsernode/Android.mk   include $(PV_TOP)//nodes/pvamrffparsernode/Android.mk   include $(PV_TOP)//nodes/pvmediaoutputnode/Android.mk   include $(PV_TOP)//nodes/pvomxvideodecnode/Android.mk   include $(PV_TOP)//nodes/pvomxaudiodecnode/Android.mk   include $(PV_TOP)//nodes/pvwavffparsernode/Android.mk   include $(PV_TOP)//pvmi/recognizer/Android.mk   include $(PV_TOP)//pvmi/recognizer/plugins/pvamrffrecognizer/Android.mk   include $(PV_TOP)//pvmi/recognizer/plugins/pvmp3ffrecognizer/Android.mk   include $(PV_TOP)//pvmi/recognizer/plugins/pvwavffrecognizer/Android.mk   include $(PV_TOP)//engines/common/Android.mk   include $(PV_TOP)//engines/adapters/player/framemetadatautility/Android.mk   include $(PV_TOP)//protocols/rtp_payload_parser/util/Android.mk   include $(PV_TOP)//android/Android.mk   include $(PV_TOP)//android/drm/oma1/Android.mk   include $(PV_TOP)//tools_v2/build/modules/linux_rtsp/core/Android.mk  include $(PV_TOP)//tools_v2/build/modules/linux_rtsp/node_registry/Android.mk   include $(PV_TOP)//tools_v2/build/modules/linux_net_support/core/Android.mk   include $(PV_TOP)//tools_v2/build/modules/linux_download/core/Android.mk   include $(PV_TOP)//tools_v2/build/modules/linux_download/node_registry/Android.mk   include $(PV_TOP)//tools_v2/build/modules/linux_mp4/core/Android.mk   include $(PV_TOP)//tools_v2/build/modules/linux_mp4/node_registry/Android.mk   libopencoreplayer.so中包含了以下内容:   * 一些解码工具   * 文件的解析器(mp4)   * 解码工具对应的Node   * player的引擎部分(engines/player/Android.mk)   * 为Android的player适配器(android/Android.mk)   * 识别工具(pvmi/recognizer)   * 编解码工具中的OpenMax部分(codecs_v2/omx)   * 对应几个插件Node的注册   libopencoreplayer.so中的内容较多,其中主要为各个文件解析器和解码器,PVPlayer的核心功能在engines/player /Android.mk当中,而android/Android.mk的内容比较特殊,它是在PVPlayer之上构建的一个为Android使用的播放器。   4.libopencoreauthor.so库的结构   libopencoreauthor.so是用于媒体流记录的功能库,它的编译控制的文件的路径为pvauthor/Android.mk,它包含了以下的内容:   include $(BUILD_SHARED_LIBRARY)   include $(PV_TOP)//engines/author/Android.mk   include $(PV_TOP)//codecs_v2/video/m4v_h263/enc/Android.mk   include $(PV_TOP)//codecs_v2/audio/gsm_amr/amr_nb/enc/Android.mk   include $(PV_TOP)//codecs_v2/video/avc_h264/enc/Android.mk   include $(PV_TOP)//fileformats/mp4/composer/Android.mk   include $(PV_TOP)//nodes/pvamrencnode/Android.mk   include $(PV_TOP)//nodes/pvmp4ffcomposernode/Android.mk   include $(PV_TOP)//nodes/pvvideoencnode/Android.mk   include $(PV_TOP)//nodes/pvavcencnode/Android.mk   include $(PV_TOP)//nodes/pvmediainputnode/Android.mk include $(PV_TOP)//android/author/Android.mk   libopencoreauthor.so中包含了以下内容:   * 一些编码工具(视频流H263、H264,音频流Amr)   * 文件的组成器(mp4)   * 编码工具对应的Node   * 表示媒体输入的Node(nodes/pvmediainputnode/Android.m)   * author的引擎部分(engines/author/Android.mk)   * 为Android的author适配器(android/author/Android.mk)   libopencoreauthor.so中主要为各个文件编码器和文件组成器,PVAuthor的核心功能在engines/author /Android.mk当中,而android/author/Android.mk是在PVAuthor之上构建的一个为Android使用的媒体记录器。   5.其他库   另外的几个库的Android.mk文件的路径如下所示:   网络支持库libopencorenet_support.so:   tools_v2/build/modules/linux_net_support/core/Android.mk   MP4功能实现库libopencoremp4.so和注册库libopencoremp4reg.so:   tools_v2/build/modules/linux_mp4/core/Android.mk   tools_v2/build/modules/linux_mp4/node_registry/Android.mk   RTSP功能实现库libopencorertsp.so和注册库libopencorertspreg.so:   tools_v2/build/modules/linux_rtsp/core/Android.mk   tools_v2/build/modules/linux_rtsp/node_registry/Android.mk   下载功能实现库libopencoredownload.so和注册库libopencoredownloadreg.so:   tools_v2/build/modules/linux_download/core/Android.mk   tools_v2/build/modules/linux_download/node_registry/Android.mk Android 五大基本组件之 Service 篇 把service的一些特性总结一下,基本知识就不介绍了.   1、主要在后台运行。   2、分两种类型:   remote和location(远程和本地)   区别:远程的可以用在不同进程间访问,通过aidl实现(aidl以后介绍),当访问的进程结束掉后,还可以在后台继续进行。   本地的是在同一个进程间访问,当访问的进程结束后一起关掉。   3、打开service的方法有两种:   一种:直接打开法:   通过startservice(Intent)这个方法打开,与之对应的是stopservice(Intent)这个方法关闭。   二种:通过bind的方法:   通过bindservice这个方法打开连接上service,与之对应该的是unbindservice这个方法断掉连接并关闭service.   需要注意的是:   (1)第一种方法只能打开service让它先运行起来,如果其它应用要使用他必须得bindService(Intent,ServiceConnection,int),然后再生成一个service的对象,就可以引用这个service对象里的方法了。   (2)如果用第一种方法打开,必须用stopservice关闭service,如果末调用stopservice,本地service有的时候应用程序虽然已经退出了,但是这个进程还末被系统回收,service还会运行,远程也需要自己关。   (3)如果第一种方法打开,每个应用想bind这个service时,需要掉用bindservice,如果不想连接了就只需要掉用 unbindservice,这个只是断开与service的连接,而service还在后台运行,此时过程中service在startservice 时调用oncreate()-->onstart(),在stopservice时调用onDestroy().   (4)如果service在bind之前末打开service,应用可以通过bindservice这个方法先打开service再连接service, 这就是上面说的第二种打开方法,这种方法在调用unbindservice时不但会断掉连接还会关闭service,此时过程中service在 bindservice时调用oncreate()-->onbind(),在unbindservice时调用 onunbind()--->onDestroy().   建议:   当有多处应用要访问一个远程的service时,可以先启动service在后台运行,然后在每一个应用中bind这个service,这样的话很方便,而且在应用程序中打开service也会快一点。 Android 数据存储之 ContentProvider、 我们简要的对SQLite进行回顾,然后将SQLite的事务管理和SQLiteDataBase提供的Insert、Update、Delete、Query方法进行了简单的讲解。   今日的重点内容是ContentProvider(内容提供者)和网络存储,我将对这两大内容进行总结。关于SQLiteDataBase提供的便捷方法,它们会在ContentProvider被使用。SQLite的事务管理比较简单,昨天有简要介绍,今日就不做总结了。   ContentProvider和网络存储将分为两篇日志,本篇总结ContentProvider。   一、ContentProvider简介   当应用继承ContentProvider类,并重写该类用于提供数据和存储数据的方法,就可以向其他应用共享其数据。虽然使用其他方法也可以对外共享数据,但数据访问方式会因数据存储的方式而不同,如:采用文件方式对外共享数据,需要进行文件操作读写数据;采用sharedpreferences共享数据,需要使用sharedpreferences API读写数据。而使用ContentProvider共享数据的好处是统一了数据访问方式。   二、Uri类简介   Uri代表了要操作的数据,Uri主要包含了两部分信息:1.需要操作的ContentProvider ,2.对ContentProvider中的什么数据进行操作,一个Uri由以下几部分组成:   1.scheme:ContentProvider(内容提供者)的scheme已经由Android所为:content://。   2.主机名(或Authority):用于唯一标识这个ContentProvider,外部调用者可以根据这个标识来找到它。   3.路径(path):可以用来表示我们要操作的数据,路径的构建应根据业务而定,如下:   · 要操作contact表中id为10的记录,可以构建这样的路径:/contact/10   · 要操作contact表中id为10的记录的name字段, contact/10/name   · 要操作contact表中的所有记录,可以构建这样的路径:/contact   要操作的数据不一定来自数据库,也可以是文件等他存储方式,如下:   要操作xml文件中contact节点下的name节点,可以构建这样的路径:/contact/name   如果要把一个字符串转换成Uri,可以使用Uri类中的parse()方法,如下:   Uri uri = Uri.parse("content://com.changcheng.provider.contactprovider/contact")   三、UriMatcher、ContentUrist和ContentResolver简介   因为Uri代表了要操作的数据,所以我们很经常需要解析Uri,并从Uri中获取数据。Android系统提供了两个用于操作Uri的工具类,分别为UriMatcher 和ContentUris 。掌握它们的使用,会便于我们的开发工作。   UriMatcher:用于匹配Uri,它的用法如下:   1.首先把你需要匹配Uri路径全部给注册上,如下:   //常量UriMatcher.NO_MATCH表示不匹配任何路径的返回码(-1)。   UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);   //如果match()方法匹配content://com.changcheng.sqlite.provider.contactprovider/contact路径,返回匹配码为1   uriMatcher.addURI(“com.changcheng.sqlite.provider.contactprovider”, “contact”, 1);//添加需要匹配uri,如果匹配就会返回匹配码   //如果match()方法匹配 content://com.changcheng.sqlite.provider.contactprovider/contact/230路径,返回匹配码为2   uriMatcher.addURI(“com.changcheng.sqlite.provider.contactprovider”, “contact/#”, 2);//#号为通配符   2.注册完需要匹配的Uri后,就可以使用uriMatcher.match(uri)方法对输入的Uri进行匹配,如果匹配就返回匹配码,匹配码是调用addURI()方法传入的第三个参数,假设匹配content://com.changcheng.sqlite.provider.contactprovider/contact路径,返回的匹配码为1。   ContentUris:用于获取Uri路径后面的ID部分,它有两个比较实用的方法:   · withAppendedId(uri, id)用于为路径加上ID部分   · parseId(uri)方法用于从路径中获取ID部分   ContentResolver:当外部应用需要对ContentProvider中的数据进行添加、删除、修改和查询操作时,可以使用ContentResolver 类来完成,要获取ContentResolver 对象,可以使用Activity提供的getContentResolver()方法。 ContentResolver使用insert、delete、update、query方法,来操作数据。   四、ContentProvider示例程序   我们为昨天的SQLite示例程序添加一个ContentProvider,供其他应用来访问我们的数据。   1.为SQLite示例程序添加ContentProvider类   package com.changcheng.sqlite.provider;   import com.changcheng.sqlite.MyOpenHelper;   import android.content.ContentProvider;   import android.content.ContentUris;   import android.content.ContentValues;   import android.content.UriMatcher;  import android.database.Cursor;   import android.database.sqlite.SQLiteDatabase;   import android.net.Uri;   public class ContactContentProvider extends ContentProvider {   // 通过UriMatcher匹配外部请求   private static UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);   // 通过openHelper进行数据库读写   private MyOpenHelper openHelper;   // 匹配状态常量   private static final int CONTACT_LIST = 1;   private static final int CONTACT = 2;   // 表名   private static final String tableName = "contacts";   // 添加Uri   static {   uriMatcher.addURI("com.changcheng.sqlite.provider", "contact",   CONTACT_LIST);   uriMatcher.addURI("com.changcheng.sqlite.provider", "contact/#",   CONTACT);   }   @Override   public int delete(Uri uri, String selection, String[] selectionArgs) {   SQLiteDatabase db = this.openHelper.getWritableDatabase();   int result;   switch (uriMatcher.match(uri)) {   case CONTACT_LIST:   result = db.delete(tableName, selection, selectionArgs);   break;   case CONTACT:   long id = ContentUris.parseId(uri);   String where = "_id=" + id;   if (selection != null && !"".equals(selection)) {   where = where + " and " + selection;   }   result = db.delete(tableName, where, selectionArgs);   break;   default:   throw new IllegalArgumentException("Uri IllegalArgument:" + uri);   }   return result;   }   @Override   public String getType(Uri uri) {   switch (uriMatcher.match(uri)) {   case CONTACT_LIST:// 集合类型必须在前面加上vnd.android.cursor.dir/   return "vnd.android.cursor.dir/contactlist"; case CONTACT:// 非集合类型必须在前面加上vnd.android.cursor.item/   return "vnd.android.cursor.item/contact";   default:   throw new IllegalArgumentException("Uri IllegalArgument:" + uri);   }   }   @Override   public Uri insert(Uri uri, ContentValues values) {   SQLiteDatabase db = this.openHelper.getWritableDatabase();   long id;   switch (uriMatcher.match(uri)) {   case CONTACT_LIST:   // 因为后台需要生成SQL语句,当values为null时,必须提第二个参数。生成的SQL语句才不会出错!   id = db.insert(tableName, "_id", values);   return ContentUris.withAppendedId(uri, id);   case CONTACT:   id = db.insert(tableName, "_id", values);   String uriPath = uri.toString();   String path = uriPath.substring(0, uriPath.lastIndexOf("/")) + id;   return Uri.parse(path);   default:   throw new IllegalArgumentException("Uri IllegalArgument:" + uri);   }   }   @Override   public boolean onCreate() {   this.openHelper = new MyOpenHelper(this.getContext());   return true;   }   @Override   public Cursor query(Uri uri, String[] projection, String selection,   String[] selectionArgs, String sortOrder) {   SQLiteDatabase db = this.openHelper.getWritableDatabase();   switch (uriMatcher.match(uri)) {   case CONTACT_LIST:   return db.query(tableName, projection, selection, selectionArgs,   null, null, sortOrder);   case CONTACT:   long id = ContentUris.parseId(uri);   String where = "_id=" + id;   if (selection != null && !"".equals(selection)) {   where = where + " and " + selection;   }   return db.query(tableName, projection, where, selectionArgs, null, null, sortOrder);   default:   throw new IllegalArgumentException("Uri IllegalArgument:" + uri);   }   }   @Override   public int update(Uri uri, ContentValues values, String selection,   String[] selectionArgs) {   SQLiteDatabase db = this.openHelper.getWritableDatabase();   int result;   switch (uriMatcher.match(uri)) {   case CONTACT_LIST:   result = db.update(selection, values, selection, selectionArgs);   break;   case CONTACT:   long id = ContentUris.parseId(uri);   String where = "_id=" + id;   if (selection != null && !"".equals(selection)) {   where = where + " and " + selection;   }   result = db.update(tableName, values, where, selectionArgs);   break;   default:   throw new IllegalArgumentException("Uri IllegalArgument:" + uri);   }   return result;   }   }   2.添加ContentProvider配置   3.测试SQLite示例程序的ContentProvider   ContentProvider即然是提供给其他应用访问本应用数据的,所以我们需要另创建一个Android应用,来测试SQLite示例程序的ContentProvider。我在此只列出query的测试方法testQuery:   public void testQuery() throws Throwable {   ContentResolver contentResolver = this.getContext()   .getContentResolver();   Uri uri = Uri   .parse("content://com.changcheng.sqlite.provider/contact");   Cursor cursor = contentResolver.query(uri, new String[] { "_id",   "name", "phone" }, null, null, "_id desc");   while (cursor.moveToNext()) {   Log.i(TAG, "_id=" + cursor.getInt(0) + ",name="   + cursor.getString(1) + ",phone=" + cursor.getString(2));   }   } 使用自定义的 Activity 栈来管理 Android 的A ctivity 在进行BlackBerry程序开发的时候,BlackBerry提供了一个管理Screen的栈,用来从任何地方来关闭位于最上一层的Screen,使用UiApplication.getUiApplication().getActiveScreen()来得到位于最上一层的Screen的实例,并且使用UiApplication.getUiApplication().popScreen()来关闭一个Screen或关闭当前最上一层的 Screen,但是Android却未提供相应的功能,只能在一个Activity的对象里面调用finish来关闭自己,不能关闭其他的 Activity。比如我们想实现一个功能从屏幕A—>屏幕B—>屏幕C—>屏幕D,然后在在转到屏幕D之前将屏幕B和C关闭,在屏幕 B和屏幕C界面点击会退按钮都可以回退到上一个屏幕,但是在屏幕D上点击会退按钮让其回退到A,此外在一些循环跳转的界面上如果不在合适的地方将一些不需要的屏幕关闭,那么经过多次跳转后回导致内存溢出。对此我们可以一个全局的Activity栈,使用这个栈来管理Activity。管理 Activity的类的定义如下:   Java代码   1. import java.util.Stack;   2.   3. import android.app.Activity;   4.   5. public class ScreenManager {   6. private static Stack activityStack;   7. private static ScreenManager instance;   8. private ScreenManager(){   9. }   10. public static ScreenManager getScreenManager(){   11. if(instance==null){   12. instance=new ScreenManager();   13. }   14. return instance;   15. }   16. public void popActivity(){   17. Activity activity=activityStack.lastElement();   18. if(activity!=null){   19. activity.finish();   20. activity=null;   21. }   22. }   23. public void popActivity(Activity activity){   24. if(activity!=null){   25. activity.finish();   26. activityStack.remove(activity);   27. activity=null;   28. }   29. }   30. public Activity currentActivity(){   31. Activity activity=activityStack.lastElement();   32. return activity; 33. }   34. public void pushActivity(Activity activity){   35. if(activityStack==null){   36. activityStack=new Stack();   37. }   38. activi
/
本文档为【Android手机开发网整理资料】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索