随笔-4  评论-0  文章-0  trackbacks-0
  2008年6月12日
 转摘 http://www.cnblogs.com/jocc/archive/2007/11/25/971511.html
AndroidManifest.xml是每个android程序中必须的文件。它位于application的根目录,描述了package中的全局数据,包括了package中暴露的组件(activities, services, 等等),他们各自的实现类,各种能被处理的数据和启动位置。

    此文件一个重要的地方就是它所包含的intent-filters。这些filters描述了activity启动的位置和时间。每当一个activity(或者操作系统)要执行一个操作,例如:打开网页或联系簿时,它创建出一个intent的对象。它能承载一些信息描述了你想做什么,你想处理什么数据,数据的类型,和一些其他信息。Android比较了intent对象中和每个application所暴露的intent-filter中的信息,来找到最合适的activity来处理调用者所指定的数据和操作。关于intent的更多信息请访问Intent参考页面。

    除了能声明你程序中的Activities, Content Providers, Services, 和Intent Receivers,你还能指定permissions和instrumentation(安全控制和测试)在AndroidManifest.xml文件中。请见AndroidManifest标记和属性的参考。

    这是一个简单的AndroidManifest.xml。

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

        package="com.my_domain.app.helloactivity">

        

    <application android:label="@string/app_name">

    

        <activity class=".HelloActivity">

            <intent-filter>

                <action android:value="android.intent.action.MAIN"/>

                <category android:value="android.intent.category.LAUNCHER"/>

            </intent-filter>

        </activity>

        

    </application>

    

</manifest>

值得一提一些常用之处:

  • 几乎所有的AndroidManifest.xml(以及许多其他Android的xml的文件)在第一个元素中包含了命名空间的声明xmlns:android="http://schemas.android.com/apk/res/android"。这样使得Android中各种标准属性能在文件中使用,提供了大部分元素中的数据。
  • 大部分manifests包含了单个<application>的元素,它定义了所有的application级别组件和属性,并能在package中使用。
  • 任何被用户看作顶层应用程序,并能被程序启动器所用的package,需要包含至少一个Activity组件来支持MAIN操作和LAUNCHER种类,如上述代码中所见。

这里是AndroidManifest.xml文件结构的一个详细的列表,描述了所有能被使用的标记。

manifest

    根节点,描述了package中所有的内容。在它之下能放置:

    uses-permission

        请求你的package正常运作所需赋予的安全许可。见Security Model来获得许可的更多的信息。一个manifest能包含零个或更多此元素。

    permission

        声明了安全许可来限制哪些程序能你package中的组件和功能。见Security Model来获得许可的更多的信息。一个manifest能包含零个或更多此元素。

    instrumentation

        声明了用来测试此package或其他package指令组件的代码。见Instrumentation来获得许可的更多的信息。一个manifest能包含零个或更多此元素。

    application

        包含package中application级别组件声明的根节点。此元素也可包含application中全局和默认的属性,如标签,icon,主题,必要的权限,等等。一个manifest能包含零个或一个此元素(不允许多余一个)。在它之下能放置零个或更多下列组件声明:

        activity

            Activity是用来与用户交互的主要工具。当用户打开一个应用程序的初始页面时一个activity,大部分被使用到的其他页面也由不同的activity所实现并声明在另外的activity标记中。

            注意:每一个activity必须要一个<activity>标记对应,无论它给外部使用或是只用于自己的package中。如果一个activity没有对应的标记,你将不能运行它。

            另外,为了支持运行时迟查找你的activity,你能包含一个或多个<intent-filter>元素来描述你activity所支持的操作:

            

            intent-filter

                声明了指定的一组组件支持的Intent值,从而形成了IntentFilter。除了能在此元素下指定不同类型的值,属性也能放在这里来描述一个操作所需的唯一的标签,icon和其它信息。

                action

                    组件支持的Intent action

                category

                    组件支持的Intent Category.

                type

                    组件支持的Intent data MIME type.

                schema

                    组件支持的Intent data URI scheme.

                authority

                    组件支持的Intent data URI authority.

                path

                    组件支持的Intent data URI path.

        receiver

            IntentReceiver能使的application获得数据的改变或者发生的操作,即使它当前不在运行。利用activity标记,你能选择地包含一个或多个receiver所支持的<intent-filter>元素;

        service

            Service是能在后台运行任意时间的组件。利用activity标记,你能选择地包含一个或多个receiver所支持的<intent-filter>元素;

        provider

            ContentProvider是用来管理持久化数据并发布给其他应用程序使用的组件。

posted @ 2008-06-12 14:08 火炼子 阅读(451) | 评论 (0)编辑 收藏
  2008年5月21日

1 四种方式配置Configuration:
传递一个java.util.Properties给Configuration.setProperties();
放置hibernate.properties在classpath路径下;
设置System属性,java -D property=value;
在hibernate.cfg.xml放置<property>元素。

Configuration cfg = new Configuration()
  .addClass()
  .addProperty(


2 获取SessionFactory:如果有多个database, 可以获取多个。

SessionFactory sessions = cfg.buildSessionFactory();


3 JDBC connections

Session session = sessions.openSession();

为了获取connection,我们需要传递一些属性给Hiberante,以下的属性定义在org.hibernate.cfg.Environment.
Hibernate通过java.sql.DriverManager获取connection.
这些属性包括:
hibernate.connection.driver_class
hibernate.connection.url
hibernate.connection.username
hibernate.connection.password
hibernate.connection.pool_size
Hibernate Datasource 属性:
hibernate.connection.datasource
hibernate.jndi.url
hibernate.jndi.class
hibernate.connection.username
hibernate.connection.password

4 可选择的hibernate 属性
hibernate.dialect: 常用的有:org.hibernate.dialect.MySQLDialect, OracleDialect,Oracle9Dialect,SQLServerDialect
hibernate.show_sql
...

5 Hibernate 日志
Hibernate使用Apache commons-logging.

6 XML配置文件
...
<hibernate-configuration>
 <session-factory name"">
  <property>
  ...
 </session-factory>
</hibernate-configuration>

SessionFactory sf = new Configuration()
  .configure(
"xxx.xml"//可以缺省xxx.xml
  .buildSessionFactory();

 

posted @ 2008-05-21 17:44 火炼子 阅读(2248) | 评论 (0)编辑 收藏
仅列出标题