




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
android application architectureauthor:lars vogel1、androidmanifest.xml the components and settings of an android application are described in the file androidmanifest.xml. for example all activities and services of the application must be declared in this file. it must also contain the required permissions for the application. for example if the application requires network access it must be specified here.the package attribute defines the base package for the java objects referred to in this file. if a java object lies within a different package, it must be declared with the full qualified package name. google play requires that every android application uses its own unique package. therefore it is a good habit to use your reverse domain name as package name. this will avoid collisions with other android applications. android:versionname and android:versioncode specify the version of your application. versionname is what the user sees and can be any string. versioncode must be an integer. the android market determine based on the versioncode, if it should perform an update of the applications for the existing installations. you typically start with 1 and increase this value by one, if you roll-out a new version of your application. the tag defines an activity, in this example pointing to the convert class in the de.vogella.android.temperature package. an intent filter is registered for this class which defines that this activity is started once the application starts (action android:name=ent.action.main). the category definition category android:name=ent.category.launcher defines that this application is added to the application directory on the android device. the string/app_name value refers to resource files which contain the actual value of the application name. the usage of resource file makes it easy to provide different resources, e.g. strings, colors, icons, for different devices and makes it easy to translate applications. the uses-sdk part of the androidmanifest.xml file defines the minimal sdk version for which your application is valid. this will prevent your application being installed on devices with older sdk versions. 2、r.java and resources the gen directory in an android project contains generated values. r.java is a generated class which contains references to certain resources of the project. these resources must be defined in the res directory and can be xml files, icons or pictures. you can for example define values, menus, layouts or animations via xml files. if you create a new resource, the corresponding reference is automatically created in r.java via the eclipse adt tools. these references are static int values and define ids for the resources. the android system provides methods to access the corresponding resource via these ids. for example to access a string with the r.string.yourstring id, you would use the getstring(r.string.yourstring) method. r.java is automatically created by the eclipse development environment, manual changes are not necessary and will be overridden by the tooling. 3、assets while the res directory contains structured values which are known to the android platform, the assets directory can be used to store any kind of data. you access this data via the assetsmanager which you can access the getassets() method. assetsmanager allows to read an assets as inputstream with the open() method./ get the assetmanagerassetmanager manager = getassets();/ read a bitmap from assetstry inputstream open = manager.open(logo.png);bitmap bitmap = bitmapfactory.decodestream(open);/ assign the bitmap to an imageview in this layoutimageview view = (imageview) findviewbyid(r.id.imageview1);view.setimagebitmap(bitmap); catch (ioexception e) e.printstacktrace();4、activities and layouts the user interface for activities is defined via layouts. the layout defines the included views (widgets) and their properties. a layout can be defined via java code or via xml. in most cases the layout is defined as an xml file. xml based layouts are defined via a resource file in the /res/layout folder. this file specifies the viewgroups, views, their relationship and their attributes for this specific layout. if a view needs to be accessed via java code, you have to give the view a unique id via the android:id attribute. to assign a new id to a view use +id/yourvalue. the following shows an example in which a button gets the button1 id assigned. by conversion this will create and assign a new yourvalue id to the corresponding view. in your java code you can later access a view via the method findviewbyid(r.id.yourvalue). defining layouts via xml is usually the preferred way as this separates the programming logic from the layout definition. it also allows the definition of different layouts for different devices. you can also mix both approaches. 5、reference to resources in xml files in your xml files, for example your layout files, you can refer to other resources via the sign. for example, if you want to refer to a color which is defined in a xml resource, you can refer to it via color/your_id. or if you defined a hello string in an xml resource, you could access it via string/hello. 6、activities and lifecycle the android system controls the lifecycle of your application. at any time the android system may stop or destroy your application, e.g. because of an incoming call. the android system defines a lifecycle for activities via predefined methods. the most important methods are: onsaveinstancestate() - called if the activity is stopped. used to save data so that the activity can restore its states if re-started onpause() - always called if the activity ends, can be used to release resource or save data onresume() - called if the activity is re-started, can be used to initialize fields 7、configuration change an activity will also be restarted, if a so called configuration change happens. a configuration change happens if an event is triggered which may be relevant for the application. for example if the user changes the orientation of the device (vertically or horizontally). android assumes that an activity might want to use different resources for these orientations and restarts the activity. in the emulator you can simulate the change of the orientation via cntr+f11. you can avoid a restart of your application for certain configuration changes via the configchanges attribute on your activity definition in your androidmanifest.xml. the following activity will not be restarted in case of orientation changes or position of the physical keyboard (hidden / visible). 8、context the class android.content.context provides the connections to the android system. it is the interface to global information about the application environment. context also provides access to android services, e.g. the location service. activities and services extend the context class and can therefore be used as context.android应用架构作者:lars vogel(拉尔斯沃格尔)1、androidmanifest.xml 一个android应用程序的组件和设置描述文件中的androidmanifest.xml。例如,应用程序的所有活动和服务,必须在这个文件中声明。它也必须包含应用程序所需的权限。例如,如果应用程序需要访问网络,它必须在这里指定。包属性定义在这个文件中提到的java 对象的基本包。如果一个java对象位于不同的包内,这必须声明的完整包名。google play 要求,每一个android应用程序使用其唯一的包。因此,使用反向域名作为包名是推荐方式。这将避免与其他android应用程序的冲突。android:versionname和android:versioncode指定的应用程序版本。 versionname是用户看到的,可以是任何字符串。versioncode必须为整数。 android market的确定根据上versioncode,是否应该对现有装置的应用进行更新。你通常用“1”和增加这个值,如果转出您的应用程序的新版本。标签定义活动,在此指向在de.vogella.android.temperature包convert类的例子。意图过滤器注册这个类的定义,这个活动开始(action android:name=ent.action.main)自从应用程序开始时。这个类定义类别android:name=ent.category.launcher 定义该应用程序被添加到android设备上的应用程序目录。string/ app_name的值是指资源文件,其中包含应用程序的名称的实际价值。使用资源文件,可以很容易地提供不同的资源,如字符串,颜色,图标,为不同的设备,可以很容易地转化应用。“androidmanifest.xml”文件的“uses-sdk”部分定义了最小的sdk版本,为您的应用程序是有效的。这将防止您的应用程序被安装在与旧的sdk版本的设备上。2、r.java文件和资源 在一个android项目中,“gen”目录包含生成的值。 r.java文件是一个自动生成的类,其中包含引用某些资源的项目。 这些资源必须定义在“res”目录中,可以是xml文件,图标或图片。例如,通过xml文件,您可以定义值,菜单布局或动画。如果你创建一个新的资源,相应的参考会自动创建在r.java文件通过eclipse adt的工具。这些引用是静态的int值和定义id的资源。 android系统提供的方法通过这些id来访问相应的资源。 例如访问一个string与r.string.yourstring id,你会使用的getstring(r.string.yourstring)的方法。r.java文件是eclipse开发环境自动创建的,手动更改是没有必要并且将通过工具重写。3、assets 众所周知android平台“res”目录包含结构化的值,这些资源目录可以用来存储任何类型的数据。您可以访问这些数据通过assetsmanager类的getassets()方法访问。assetsmanager类允许读取资源输出流,通过open()方法。/ 得到 assetmanagerassetmanager manager = getassets();/ 从资源中读取一张位图try inputstream open = manager.open(logo.png);bitmap bitmap = bitmapfactory.decodestream(open);/ 指定位图到imageviewimageview view = (imageview) findviewbyid(r.id.imageview1);view.setimagebitmap(bitmap); catch (ioexception e) e.printstacktrace();4、活动和布局 用户接口是通过布局定义的活动,布局定义所包含的意见(部件)及其属性。 一个布局可以通过java代码或是通过xml定义,在大多数案例中,布局被定义为一个xml文件。 基于xml布局被定义通过一个资源文件在/ res/ layout文件夹中,这个文件专门为了这个特别的布局的viewsgroups、views、他们的关系和属性。 如果一个视图需要通过java代码来访问,你必须通过android:i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025版基础设施建设项目融资担保借款合同
- 二零二五年度二手房买卖合同含物业费结算及调整
- 2025版绿色生态停车场建筑施工装修合同
- 二零二五年度商铺租赁合同范本下载
- 2025版智能农业机耕与植保服务合同
- 二零二五年度粮食储备居间服务合同
- 二零二五年度煤气管道维护及安全保障合同
- 二零二五年度重型卡车全方位维修及改装合同
- 2025至2030年中国百洁布行业市场发展现状及投资战略咨询报告
- 二零二五年度办公空间租赁及增值服务合同
- 小学数学知识体系构建研究课题
- 《变电运行培训》课件
- 幼儿发展的关键指标与行为观察
- 班主任工作手册(适合中小学)
- 瑜伽生活方式中心生活馆项目建议书
- 高二主题班会课件我的未来不是梦2
- 吊装作业票(样本)
- 【新课标】2022版小学数学课标之模拟卷6套
- 固体矿产钻探工真题模拟汇编(共634题)
- 生产车间6S现场管理培训
- 第34届全国中学生物理竞赛决赛试题及答案
评论
0/150
提交评论