当前位置:  编程技术>移动开发
本页文章导读:
    ▪Application Fundamentals-Intent 过滤器        Application Fundamentals--Intent 过滤器 Intent 过滤器Intent 对象可以显式指定目标组件.一旦显式指定了目标组件,Android 操作系统直接根据指定的目标组件名在AndroidManifest.xml文件中查找该组件声明.........
    ▪ 相仿selector的效果        类似selector的效果 selector通常要求我们好几张图片,可是有时候我只需要一张图片不同的是只是颜色变化而已 button.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);  button.getBackground().setC.........
    ▪ Application Fundamentals-Activities and Tasks       Application Fundamentals--Activities and Tasks Activities and TasksAs noted earlier, one activity can start another, including one defined in a different application. Suppose, for example, that you'd like to let users display a street map of some .........

[1]Application Fundamentals-Intent 过滤器
    来源: 互联网  发布时间: 2014-02-18
Application Fundamentals--Intent 过滤器
Intent 过滤器

Intent 对象可以显式指定目标组件.一旦显式指定了目标组件,Android 操作系统直接根据指定的目标组件名在AndroidManifest.xml文件中查找该组件声明,找到之后立即激活该组件。如果Intent 对象没有显式指定目标组件, Android 操作系统必须从AndroidManifest.xml文件中的所有intent过滤器中定位到一个最佳匹配的intent声明. 匹配过程事实上是把该 Intent 对象与 intent filters 中定义的intent元素做比对,一旦比对成功,Intent 过滤器立即通知Android 操作系统该过滤器所归属的组件可以响应该intent对象的操作请求,下面是是两个过滤器元素的相关定义:

<?xml version="1.0" encoding="utf-8"?>
<manifest . . . >
    <application . . . >
        <activity android:name="com.example.project.FreneticActivity"
                  android:icon="@drawable/small_pic.png"
                  android:label="@string/freneticLabel"
                  . . .  >
            <intent-filter . . . >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter . . . >
                <action android:name="com.example.project.BOUNCE" />
                <data android:mimeType="image/jpeg" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        . . .
    </application>
</manifest>

第一个过滤器元素 — 包含 action 属性= "android.intent.action.MAIN" 和category 属性= "android.intent.category.LAUNCHER" — 这两个属性定义表示的含义是. 该 activity 应该显示在application 发射台上,用户可以在发射台上启动该应用 . 换句话说该 activity 是该应用程序的启动入口。

第二个过滤器元素同样包含了一个action属性,属性值是自定义的,表示该 activity 可以处理特定类型的数据.

AndroidManifest.xml文件中的组件元素可以有任意个intent filters,每个过滤器都声明了该组件的一种不同的能力. 如果一个组件没有定义过滤器元素,那么该组件只能被显式定义了组件名的intent对象激活。

For a broadcast receiver that's created and registered in code, the intent filter is instantiated directly as an IntentFilter object. All other filters are set up in the manifest.

For more on intent filters, see a separate document, Intents and Intent Filters.

    
[2] 相仿selector的效果
    来源: 互联网  发布时间: 2014-02-18
类似selector的效果

selector通常要求我们好几张图片,可是有时候我只需要一张图片不同的是只是颜色变化而已

button.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY); 

button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000));

 

2.

background="@drawable/custom_button"

 

<?xml version="1.0" encoding="utf-8"?> 
<selector 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
 
    <item android:state_pressed="true" > 
        <shape> 
            <gradient 
                android:startColor="@color/yellow1" 
                android:endColor="@color/yellow2" 
                android:angle="270" /> 
            <stroke 
                android:width="3dp" 
                android:color="@color/grey05" /> 
            <corners 
                android:radius="3dp" /> 
            <padding 
                android:left="10dp" 
                android:top="10dp" 
                android:right="10dp" 
                android:bottom="10dp" /> 
        </shape> 
    </item> 
 
    <item android:state_focused="true" > 
        <shape> 
            <gradient 
                android:endColor="@color/orange4" 
                android:startColor="@color/orange5" 
                android:angle="270" /> 
            <stroke 
                android:width="3dp" 
                android:color="@color/grey05" /> 
            <corners 
                android:radius="3dp" /> 
            <padding 
                android:left="10dp" 
                android:top="10dp" 
                android:right="10dp" 
                android:bottom="10dp" /> 
        </shape> 
    </item> 
 
    <item>         
        <shape> 
            <gradient 
                android:endColor="@color/blue2" 
                android:startColor="@color/blue25" 
                android:angle="270" /> 
            <stroke 
                android:width="3dp" 
                android:color="@color/grey05" /> 
            <corners 
                android:radius="3dp" /> 
            <padding 
                android:left="10dp" 
                android:top="10dp" 
                android:right="10dp" 
                android:bottom="10dp" /> 
        </shape> 
    </item> 
</selector> 


    
[3] Application Fundamentals-Activities and Tasks
    来源: 互联网  发布时间: 2014-02-18
Application Fundamentals--Activities and Tasks
Activities and Tasks

As noted earlier, one activity can start another, including one defined in a different application. Suppose, for example, that you'd like to let users display a street map of some location. There's already an activity that can do that, so all your activity needs to do is put together an Intent object with the required information and pass it to startActivity(). The map viewer will display the map. When the user hits the BACK key, your activity will reappear on screen.

翻译:之前我们说过一个 activity 可以启动另外一个activity,即使是其他应用中的activity也可以被启动 . 假定:你希望让你的应用能为用户显示一条街道的地图信息,那么在你的activity中,需要做的就是给startActivity()方法传入一个intent对象来激活一个map viewer activity,这个map viewer activity 将为用户显示一条街道的地图信息。当用户按下BACK按钮时候你的activity重新出现在屏幕上。

To the user, it will seem as if the map viewer is part of the same application as your activity, even though it's defined in another application and runs in that application's process. Android maintains this user experience by keeping both activities in the same task. Simply put, a task is what the user experiences as an "application." It's a group of related activities, arranged in a stack. The root activity in the stack is the one that began the task — typically, it's an activity the user selected in the application launcher. The activity at the top of the stack is one that's currently running — the one that is the focus for user actions. When one activity starts another, the new activity is pushed on the stack; it becomes the running activity. The previous activity remains in the stack. When the user presses the BACK key, the current activity is popped from the stack, and the previous one resumes as the running activity.

翻译:对于用户而言,看上去似乎map viewer是和前面一个activity都是这个应用程序的的组成部分,而事实上这个map viewer完全可能是归属另外一个应用的进程。 Android 能够提供这样的用户体验是通过把两个activities保持在同一个task中实现的. 简单地说,task是用户体验的“应用”,一个 task 可以理解为安放在一个堆栈中的一组相关联的activities,这个堆栈中的根activity是开始这个task的起点 — 这个activity也常常是用户在应用发射台选定的activity。当一个activity启动了另外一个新的activity, 这个新的activity就被压入堆栈,成为当前运行的activity. 先前那个activity 依然保留在堆栈中. 当用户按下 BACK 键, 当前运行的activity弹出堆栈,先前保留在堆栈中的那个activity重新变成当前运行的activity.

The stack contains objects, so if a task has more than one instance of the same Activity subclass open — multiple map viewers, for example — the stack has a separate entry for each instance. Activities in the stack are never rearranged, only pushed and popped.

翻译:堆栈用来存放activity对象,所以如果说一个task中有一个Activity的多个实例的话,比如打开了多个map viewers,每个map viewers实例都是分别压入当前task堆栈的,堆栈从不会对其中的实例顺序重新排列的,堆栈做的只是简单的压入和弹出实例。

A task is a stack of activities, not a class or an element in the manifest file. So there's no way to set values for a task independently of its activities. Values for the task as a whole are set in the root activity. For example, the next section will talk about the "affinity of a task"; that value is read from the affinity set for the task's root activity.

翻译:task是由一组 activities 实例组成的堆栈,它既不是类也不是manifest文件中的元素,所以,如果要修改或约定一个task的某些行为方式必须依赖这个task(堆栈)中的 activity。具体说是要通过task堆栈中的根activitiy来实现对当前task行为方式的特殊约定。比如task的affinity属性值就需要设定在根activity上。

All the activities in a task move together as a unit. The entire task (the entire activity stack) can be brought to the foreground or sent to the background. Suppose, for instance, that the current task has four activities in its stack — three under the current activity. The user presses the HOME key, goes to the application launcher, and selects a new application (actually, a new task). The current task goes into the background and the root activity for the new task is displayed. Then, after a short period, the user goes back to the home screen and again selects the previous application (the previous task). That task, with all four activities in the stack, comes forward. When the user presses the BACK key, the screen does not display the activity the user just left (the root activity of the previous task). Rather, the activity on the top of the stack is removed and the previous activity in the same task is displayed.

翻译:task中的所有activities是作为一个整体出现在前台或是退到后台,例如task1有四个Activity在该task的堆栈中,其他三个Activity在当前运行显示的Activity下面。如果这时用户按下HOME键,屏幕将显示应用发射台界面。然后用户选中另一个应用,实际上Android系统就开始了一个新的task2,这时候之前的那个task1便退到后台,用户这时候看到的task2的根Activity界面,此时,用户可能又按下HOME键,重新选中之前那个应用,这时候task1堆栈重新来到前台,这个task1有四个Activity在自己的堆栈中,此时用户可能又按下BACK键,此时刚才显示过的那个task2的根Activity界面是不会显示出来的,实际显示的将是task1的堆栈中上一次显示过的那个 Activity的界面。总结一下,这里我们要说明的是,任何一个task堆栈中的实例都是作为一个整体来到前台或是退到后台的,用户按下BACK键将只会导致前台所关联的那个task堆栈排列顺序发生变化。

The behavior just described is the default behavior for activities and tasks. But there are ways to modify almost all aspects of it. The association of activities with tasks, and the behavior of an activity within a task, is controlled by the interaction between flags set in the Intent object that started the activity and attributes set in the activity's <activity> element in the manifest. Both requester and respondent have a say in what happens.

翻译:以上描述的规则是activities和task的默认规则,但是这个规则不是说一成不变的,是可以被修改的。要修改这个规则需要在触发 Activity的intent对象中设定flag属性值或者是设定manifest文件中Activity组件元素的相关属性值。

针对这个规则的修改,可能用来设定Intent对象的flags属性的值主要是以下几个:

FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
FLAG_ACTIVITY_SINGLE_TOP

针对这个规则的修改,涉及到manifest文件中Activity组件元素的这几个属性:

taskAffinity
launchMode
allowTaskReparenting
clearTaskOnLaunch
alwaysRetainTaskState
finishOnTaskLaunch

The following sections describe what some of these flags and attributes do, how they interact, and what considerations should govern their use.

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3