当前位置:  编程技术>移动开发
本页文章导读:
    ▪Application Fundamentals-Affinities and new tasks        Application Fundamentals--Affinities and new tasks Affinities and new tasksBy default, all the activities in an application have an affinity for each other — that is, there's a preference for them all to belong to the same task. However, an indi.........
    ▪ Manifest- Activity 属性 + 搬运回的翻译        Manifest- Activity 属性 + 搬运来的翻译 activity 属性:http://developer.android.com/guide/topics/manifest/activity-element.html免翻**墙搬运: <activity> syntax: <activity android:allowTaskReparenting=["true" | "false"] .........
    ▪ radio button批改样式       radio button修改样式 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="CustomTheme" parent="android:Theme">    <item name="android:radioButtonStyle">@style/RadioButton</item> </style> <st.........

[1]Application Fundamentals-Affinities and new tasks
    来源: 互联网  发布时间: 2014-02-18
Application Fundamentals--Affinities and new tasks
Affinities and new tasks

By default, all the activities in an application have an affinity for each other — that is, there's a preference for them all to belong to the same task. However, an individual affinity can be set for each activity with the taskAffinity attribute of the <activity> element. Activities defined in different applications can share an affinity, or activities defined in the same application can be assigned different affinities. The affinity comes into play in two circumstances: When the Intent object that launches an activity contains the FLAG_ACTIVITY_NEW_TASK flag, and when an activity has its allowTaskReparenting attribute set to "true".

翻译:默认一个应用中的所有Activity组件相互之间有同一个affinity,换句话说manifest文件中所有Activity组件同属一个task,但是你还是可以手动给Activity组件设定affinity属性值的,这就使得不同应用的Activity组件可以共享同一个affinity值或是让一个应用中的Activity组件拥有不同的affinity值。这样做只是在以下两种场合的时候才会有效:

一: intent对象中的flag属性被设定为FLAG_ACTIVITY_NEW_TASK,可以理解intent请求对象本身要求被激活的Activity以一个新task的根Activity的方式被启动。

二: manifest文件中的activity元素的allowTaskReparenting被设定为"true",这可以理解为被激活的Activity自身是允许进入其他task堆栈的。Reparent==重定父级(当某个task的 affinity属性值和这个Activity实例的affinity属性值一样的task堆栈走到前台时候,允许这个Activity实例进入这个前台堆栈中)

The FLAG_ACTIVITY_NEW_TASK--以新task方式触发Activity flag
    As described earlier, a new activity is, by default, launched into the task of the activity that called startActivity(). It's pushed onto the same stack as the caller. However, if the Intent object passed to startActivity() contains the FLAG_ACTIVITY_NEW_TASK flag, the system looks for a different task to house the new activity. Often, as the name of the flag implies, it's a new task. However, it doesn't have to be. If there's already an existing task with the same affinity as the new activity, the activity is launched into that task. If not, it begins a new task.

翻译:之前我们说过,一个Activity可以用intent对象激活另外一个Activity,默认场合这个被触发的Activity将加入前一个Activity所属的task堆栈中,但是一旦说startActivity()方法的参数:intent对象中的flag属性被设定为 FLAG_ACTIVITY_NEW_TASK,那么Android系统将为这个被激活的Activity查找拥有同样affinity的task,如果找到,该Activity将被压入找到的task 的堆栈中,如果找不到那么为这个Activity创建一个新task,并压入新task的堆栈。换句话说无论如何,这个Activity是不会进入到当期 task堆栈中的。

The allowTaskReparenting--允许进入其他task堆栈(重定父级) attribute
    If an activity has its allowTaskReparenting attribute set to "true", it can move from the task it starts into the task it has an affinity for when that task comes to the fore. For example, suppose that an activity that reports weather conditions in selected cities is defined as part of a travel application. It has the same affinity as other activities in the same application (the default affinity) and it allows reparenting. One of your activities starts the weather reporter, so it initially belongs to the same task as your activity. However, when the travel application next comes forward, the weather reporter will be reassigned to and displayed with that task.

翻译:如果一个被激活的Activity的allowTaskReparenting属性被设定为"true",这个Activity先是进入当前task堆栈。但是如果拥有同一个affinity的其他某个task来到前台的时候,该Activity可以从自己所属的task堆栈中移动到前台绑定的这个task堆栈中。也就是说这个Activity实例随时都可能离开这个堆栈进入到另外一个堆栈中。

If an .apk file contains more than one "application" from the user's point of view, you will probably want to assign different affinities to the activities associated with each of them.

翻译:以上两种场合都涉及到task的affinity值,使用task的affinity值和Activity的affinity值的目的是为了细化task,如果说你的apk文件中包含用户视觉感官的多个“应用”,那么你可能就为你的activities设定不同的affinities,这样做的目的是为了满足应用程序需要应对多个task堆栈轮番出现在前台的场合。

     我们可以做这样的总结:通常一个应用中的activities是拥有同样的affinity值的,应用与用户交互过程中产生的activities实例都将属于同一个task堆栈,但是如果说你的应用足够复杂的话,那么很可能用户在视觉感官上产生这个应用是由多个应用构成的,这时候就需要把你的应用划分为不同逻辑意义上的task,假定需要三个不同逻辑意义上task,那么你这个应用中的activities元素的affinities属性可以相应设定为三类不同的值,如果是这样,那么该应用在Android操作系统上运行的过程将会出现三个不同的task堆栈,这三个task堆栈将轮番出现在前台。

    
[2] Manifest- Activity 属性 + 搬运回的翻译
    来源: 互联网  发布时间: 2014-02-18
Manifest- Activity 属性 + 搬运来的翻译

activity 属性:
http://developer.android.com/guide/topics/manifest/activity-element.html

免翻**墙搬运:

<activity>
syntax:
<activity android:allowTaskReparenting=["true" | "false"]
          android:alwaysRetainTaskState=["true" | "false"]
          android:clearTaskOnLaunch=["true" | "false"]
          android:configChanges=["mcc", "mnc", "locale",
                                 "touchscreen", "keyboard", "keyboardHidden",
                                 "navigation", "orientation", "screenLayout",
                                 "fontScale", "uiMode"]
          android:enabled=["true" | "false"]
          android:excludeFromRecents=["true" | "false"]
          android:exported=["true" | "false"]
          android:finishOnTaskLaunch=["true" | "false"]
          android:icon="drawable resource"
          android:label="string resource"
          android:launchMode=["multiple" | "singleTop" |
                              "singleTask" | "singleInstance"]
          android:multiprocess=["true" | "false"]
          android:name="string"
          android:noHistory=["true" | "false"]  
          android:permission="string"
          android:process="string"
          android:screenOrientation=["unspecified" | "user" | "behind" |
                                     "landscape" | "portrait" |
                                     "sensor" | "nosensor"]
          android:stateNotNeeded=["true" | "false"]
          android:taskAffinity="string"
          android:theme="resource or theme"
          android:windowSoftInputMode=["stateUnspecified",
                                       "stateUnchanged", "stateHidden",
                                       "stateAlwaysHidden", "stateVisible",
                                       "stateAlwaysVisible", "adjustUnspecified",
                                       "adjustResize", "adjustPan"] >   
    . . .
</activity>
contained in: <application> can contain: <intent-filter> 
<meta-data> description: Declares an activity (an Activity subclass) that implements part of the application's visual user interface. All activities must be represented by <activity> elements in the manifest file. Any that are not declared there will not be seen by the system and will never be run. attributes: android:allowTaskReparenting Whether or not the activity can move from the task that started it to the task it has an affinity for when that task is next brought to the front — "true" if it can move, and "false" if it must remain with the task where it started.

If this attribute is not set, the value set by the corresponding allowTaskReparenting attribute of the <application> element applies to the activity. The default value is "false".

Normally when an activity is started, it's associated with the task of the activity that started it and it stays there for its entire lifetime. You can use this attribute to force it to be re-parented to the task it has an affinity for when its current task is no longer displayed. Typically, it's used to cause the activities of an application to move to the main task associated with that application.

For example, if an e-mail message contains a link to a web page, clicking the link brings up an activity that can display the page. That activity is defined by the browser application, but is launched as part of the e-mail task. If it's reparented to the browser task, it will be shown when the browser next comes to the front, and will be absent when the e-mail task again comes forward.

The affinity of an activity is defined by the taskAffinity attribute. The affinity of a task is determined by reading the affinity of its root activity. Therefore, by definition, a root activity is always in a task with the same affinity. Since activities with "singleTask" or "singleInstance" launch modes can only be at the root of a task, re-parenting is limited to the "standard" and "singleTop" modes. (See also the launchMode attribute.)

android:alwaysRetainTaskState Whether or not the state of the task that the activity is in will always be maintained by the system — "true" if it will be, and "false" if the system is allowed to reset the task to its initial state in certain situations. The default value is "false". This attribute is meaningful only for the root activity of a task; it's ignored for all other activities.

Normally, the system clears a task (removes all activities from the stack above the root activity) in certain situations when the user re-selects that task from the home screen. Typically, this is done if the user hasn't visited the task for a certain amount of time, such as 30 minutes.

However, when this attribute is "true", users will always return to the task in its last state, regardless of how they get there. This is useful, for example, in an application like the web browser where there is a lot of state (such as multiple open tabs) that users would not like to lose.

android:clearTaskOnLaunch Whether or not all activities will be removed from the task, except for the root activity, whenever it is re-launched from the home screen — "true" if the task is always stripped down to its root activity, and "false" if not. The default value is "false". This attribute is meaningful only for activities that start a new task (the root activity); it's ignored for all other activities in the task.

When the value is "true", every time users start the task again, they are brought to its root activity, regardless of what they were last doing in the task and regardless of whether they used BACK or HOME to last leave it. When the value is "false", the task may be cleared of activities in some situations (see the alwaysRetainTaskStateattribute), but not always.

Suppose, for example, that someone launches activity P from the home screen, and from there goes to activity Q. The user next presses HOME, and then returns to activity P. Normally, the user would see activity Q, since that is what they were last doing in P's task. However, if P set this flag to "true", all of the activities on top of it (Q in this case) were removed when the user pressed HOME and the task went to the background. So the user sees only P when returning to the task.

If this attribute and allowTaskReparenting are both "true", any activities that can be re-parented are moved to the task they share an affinity with; the remaining activities are then dropped, as described above.

android:configChanges Lists configuration changes that the activity will handle itself. When a configuration change occurs at runtime, the activity is shut down and restarted by default, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.

Note: Using this attribute should be avoided and used only as a last-resort. Please read Handling Runtime Changes for more information about how to properly handle a restart due to a configuration change.

Any or all of the following strings are valid values for this attribute. Multiple values are separated by '|' — for example, "locale|navigation|orientation".

Value Description "mcc" The IMSI mobile country code (MCC) has changed — a SIM has been detected and updated the MCC. "mnc" The IMSI mobile network code (MNC) has changed — a SIM has been detected and updated the MNC. "locale" The locale has changed — the user has selected a new language that text should be displayed in. "touchscreen" The touchscreen has changed. (This should never normally happen.) "keyboard" The keyboard type has changed — for example, the user has plugged in an external keyboard. "keyboardHidden" The keyboard accessibility has changed — for example, the user has revealed the hardware keyboard. "navigation" The navigation type (trackball/dpad) has changed. (This should never normally happen.) "orientation" The screen orientation has changed — the user has rotated the device. "screenLayout" The screen layout has changed — this might be caused by a different display being activated. "fontScale" The font scaling factor has changed — the user has selected a new global font size. "uiMode" The user interface mode has changed — this can be caused when the user places the device into a desk/car dock or when the the night mode changes. See UiModeManager. Introduced in API Level 8.

All of these configuration changes can impact the resource values seen by the application. Therefore, when onConfigurationChanged() is called, it will generally be necessary to again retrieve all resources (including view layouts, drawables, and so on) to correctly handle the change.

android:enabled Whether or not the activity can be instantiated by the system — "true" if it can be, and "false" if not. The default value is "true".

The <application> element has its own enabled attribute that applies to all application components, including activities. The <application> and <activity> attributes must both be "true" (as they both are by default) for the system to be able to instantiate the activity. If either is "false", it cannot be instantiated.

android:excludeFromRecents Whether or not the activity should be excluded from the list of recently launched activities that can be displayed to users — "true" if it should be excluded, and "false" if it should be included. The default value is "false".

 

android:exported Whether or not the activity can be launched by components of other applications — "true" if it can be, and "false" if not. If "false", the activity can be launched only by components of the same application or applications with the same user ID.

The default value depends on whether the activity contains intent filters. The absence of any filters means that the activity can be invoked only by specifying its exact class name. This implies that the activity is intended only for application-internal use (since others would not know the class name). So in this case, the default value is "false". On the other hand, the presence of at least one filter implies that the activity is intended for external use, so the default value is "true".

This attribute is not the only way to limit an activity's exposure to other applications. You can also use a permission to limit the external entities that can invoke the activity (see the permission attribute).

android:finishOnTaskLaunch Whether or not an existing instance of the activity should be shut down (finished) whenever the user again launches its task (chooses the task on the home screen) — "true" if it should be shut down, and "false" if not. The default value is "false".

If this attribute and allowTaskReparenting are both "true", this attribute trumps the other. The affinity of the activity is ignored. The activity is not re-parented, but destroyed.

android:icon An icon representing the activity. The icon is displayed to users when a representation of the activity is required on-screen. For example, icons for activities that initiate tasks are displayed in the launcher window. The icon is often accompanied by a label (see the label attribute).

 

This attribute must be set as a reference to a drawable resource containing the image definition. If it is not set, the icon specified for the application as a whole is used instead (see the <application> element's icon attribute).

The activity's icon — whether set here or by the <application> element — is also the default icon for all the activity's intent filters (see the <intent-filter> element's iconattribute).

android:label A user-readable label for the activity. The label is displayed on-screen when the activity must be represented to the user. It's often displayed along with the activity icon.

If this attribute is not set, the label set for the application as a whole is used instead (see the <application> element's label attribute).

The activity's label — whether set here or by the <application> element — is also the default label for all the activity's intent filters (see the <intent-filter> element's labelattribute).

The label should be set as a reference to a string resource, so that it can be localized like other strings in the user interface. However, as a convenience while you're developing the application, it can also be set as a raw string.

android:launchMode An instruction on how the activity should be launched. There are four modes that work in conjunction with activity flags (FLAG_ACTIVITY_* constants) in Intent objects to determine what should happen when the activity is called upon to handle an intent. They are:

 

"standard" 
"singleTop" 
"singleTask" 
"singleInstance"

The default mode is "standard".

As shown in the table below, the modes fall into two main groups, with "standard" and "singleTop" activities on one side, and "singleTask" and "singleInstance" activities on the other. An activity with the "standard" or "singleTop" launch mode can be instantiated multiple times. The instances can belong to any task and can be located anywhere in the activity stack. Typically, they're launched into the task that called startActivity() (unless the Intent object contains a FLAG_ACTIVITY_NEW_TASK instruction, in which case a different task is chosen — see the taskAffinity attribute).

In contrast, "singleTask" and "singleInstance" activities can only begin a task. They are always at the root of the activity stack. Moreover, the device can hold only one instance of the activity at a time — only one such task.

The "standard" and "singleTop" modes differ from each other in just one respect: Every time there's a new intent for a "standard" activity, a new instance of the class is created to respond to that intent. Each instance handles a single intent. Similarly, a new instance of a "singleTop" activity may also be created to handle a new intent. However, if the target task already has an existing instance of the activity at the top of its stack, that instance will receive the new intent (in an onNewIntent() call); a new instance is not created. In other circumstances — for example, if an existing instance of the "singleTop" activity is in the target task, but not at the top of the stack, or if it's at the top of a stack, but not in the target task — a new instance would be created and pushed on the stack.

The "singleTask" and "singleInstance" modes also differ from each other in only one respect: A "singleTask" activity allows other activities to be part of its task. It's always at the root of its task, but other activities (necessarily "standard" and "singleTop" activities) can be launched into that task. A "singleInstance" activity, on the other hand, permits no other activities to be part of its task. It's the only activity in the task. If it starts another activity, that activity is assigned to a different task — as ifFLAG_ACTIVITY_NEW_TASK was in the intent.

Use Cases Launch Mode Multiple Instances? Comments Normal launches for most activities "standard" Yes Default. The system always creates a new instance of the activity in the target task and routes the intent to it. "singleTop" Conditionally If an instance of the activity already exists at the top of the target task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity. Specialized launches
(not recommended for general use) "singleTask" No The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one. "singleInstance" No Same as "singleTask", except that the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task.

As shown in the table above, standard is the default mode and is appropriate for most types of activities. SingleTop is also a common and useful launch mode for many types of activities. The other modes — singleTask and singleInstance — are not appropriate for most applications, since they result in an interaction model that is likely to be unfamiliar to users and is very different from most other applications.

Regardless of the launch mode that you choose, make sure to test the usability of the activity during launch and when navigating back to it from other activities and tasks using the BACK key.

For more information on launch modes and their interaction with Intent flags, see the Activities and Tasks section of the Application Fundamentals document.

 

这些属性被用来处理每个应用启动和相互调用以及

相关
  • 1 Manifest中Activity的一些配备
  • 2 Activity属性设立大全
  • 3 activity属性,加载方式等
  • 4 Dialog属性的Activity运用
  • 5 (翻译)Mozilla OS APP开发:Manifest常见有关问题
移动开发-热门移动开发-最新移动开发-其它
  • 1 十分难缠的signal 11 (SIGSEGV)
  • 2 Can't create handler inside thread that has not called Looper.prepare() 错误有关问题
  • 3 Dex Loader Unable to execute Multiple dex files define解决办法
  • 4 解决 Google Play下载施用 "Google Play Store 已停止运行&quot
  • 5 WAP网页获得用户的手机号码
  • 6 如何判断Activity是否在运行
  • 7 SlidingMenu+ViewPager兑现侧滑菜单效果
  • 8 makeKeyAndVisible的功用
  • 9 关于Unable to execute dex: Java heap space 解决方法
  • 10 RelativeLayout设置居中对齐有关问题
  • 1 播发声音文件AVAudioPlayer
  • 2 改变银屏显示方式已经加载图片
  • 3 2013-十-31 TCP/IP 协议簇
  • 4 Java I/零 总体框架图
  • 5 拿碗的铠甲勇者
  • 6 女友可能出轨 想知道在QQ和别人的聊天记录
  • 7 objective C中的字符串(3)
  • 8 java.lang.ClassNotFoundException: Didn't find class "Activity" on path: /da
  • 9 LG Optimus G Pro 相干
  • 10 怎么创建对话框
  • 1 MGTemplateEngine模版发动机
  • 2 power键跟音量键组合实现截图功能
  • 3 疑惑为什么报错了
  • 4 视图切换的形式
  • 5 Tiledmap编辑操作技巧
  • 6 BroadcastReceiver要领
  • 7 Andriod耗时操作的处置(音乐播放器欢迎界面)
  • 8 用 lipo 下令裁剪出需要的 architecture
  • 9 深入viewgroup.onintercepttouchevent1点
  • 10 实现默认文字统制的textview
  • 上一篇: Application Fundamentals-Affinities and new tasks
  • 下一篇: radio button批改样式

    
[3] radio button批改样式
    来源: 互联网  发布时间: 2014-02-18
radio button修改样式

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<style name="CustomTheme" parent="android:Theme"> 
   <item name="android:radioButtonStyle">@style/RadioButton</item> 
</style> 
<style name="RadioButton" parent="@android:style/Widget.CompoundButton.RadioButton"> 
   <item name="android:button">@drawable/radio</item> 
</style> 
</resources> 

 

<?xml version="1.0" encoding="utf-8"?> 
    <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_checked="true" android:state_window_focused="false" 
        android:drawable="@drawable/radio_hover" /> 
    <item android:state_checked="false" android:state_window_focused="false" 
        android:drawable="@drawable/radio_normal" /> 
    <item android:state_checked="true" android:state_pressed="true" 
        android:drawable="@drawable/radio_active" /> 
    <item android:state_checked="false" android:state_pressed="true" 
        android:drawable="@drawable/radio_active" /> 
    <item android:state_checked="true" android:state_focused="true" 
        android:drawable="@drawable/radio_hover" /> 
    <item android:state_checked="false" android:state_focused="true" 
        android:drawable="@drawable/radio_normal_off" /> 
    <item android:state_checked="false" android:drawable="@drawable/radio_normal" /> 
    <item android:state_checked="true" android:drawable="@drawable/radio_hover" /> 
    </selector> 

 


    
最新技术文章:
▪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播放网络音频的实现方法...
javascript开源软件 iis7站长之家
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


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

©2012-2021,