【Android基础】Activity的启动模式(android:launchMode)

在android里,有4种activity的启动模式,分别为:

  • “standard” (默认)
  • “singleTop”
  • “singleTask”
  • “singleInstance”

它们主要有如下不同:

 

1. 如何决定所属task

“standard”和”singleTop”的activity的目标task,和收到的Intent的发送者在同一个task内,除非intent包括参数FLAG_ACTIVITY_NEW_TASK。

如果提供了FLAG_ACTIVITY_NEW_TASK参数,会启动到别的task里。

“singleTask”和”singleInstance”总是把activity作为一个task的根元素,他们不会被启动到一个其他task里。

这篇博文写的比较简单, 也没有任何图示, 不便大家理解, 建立大家直接看Dev guide.  或者下面这篇博文:

http://marshal.easymorse.com/archives/2950

2. 是否允许多个实例

“standard”和”singleTop”可以被实例化多次,并且存在于不同的task中,且一个task可以包括一个activity的多个实例;

“singleTask”和”singleInstance”则限制只生成一个实例,并且是task的根元素。

singleTop要求如果创建intent的时候栈顶已经有要创建 的Activity的实例,则将intent发送给该实例,而不发送给新的实例。

3. 是否允许其它activity存在于本task内

“singleInstance”独占一个task,其它activity不能存在那个task里;如果它启动了一个新的activity,不管新的activity的launch mode 如何,新的activity都将会到别的task里运行(如同加了FLAG_ACTIVITY_NEW_TASK参数)。

而另外三种模式,则可以和其它activity共存。

4. 是否每次都生成新实例

“standard”对于没一个启动Intent都会生成一个activity的新实例;

“singleTop”的activity如果在task的栈顶的话,则不生成新的该activity的实例,直接使用栈顶的实例,否则,生成该activity的实例。

比如现在task栈元素为A-B-C-D(D在栈顶),这时候给D发一个启动intent,如果D是 “standard”的,则生成D的一个新实例,栈变为A-B-C-D-D。

如果D是singleTop的话,则不会生产D的新实例,栈状态仍为A-B-C-D

如果这时候给B发Intent的话,不管B的launchmode是”standard” 还是 “singleTop” ,都会生成B的新实例,栈状态变为A-B-C-D-B。

“singleInstance”是其所在栈的唯一activity,它会每次都被重用。

“singleTask”如果在栈顶,则接受intent,否则,该intent会被丢弃,但是该task仍会回到前台。

当已经存在的activity实例处理新的intent时候,会调用onNewIntent()方法

如果收到intent生成一个activity实例,那么用户可以通过back键回到上一个状态;如果是已经存在的一个activity来处理这个intent的话,用户不能通过按back键返回到这之前的状态。

 

 

 


该文来自网络,源地址已经忘了, 原作者可以与我联系,以注明版权!

 

总结:

standard  每次都会新建,每个Task都可以有,且每个Task都可以有多个实例(每个Task都可以有,且可以有多个) singleTop 当前实例如果在栈顶,就不新建实例,调用其OnNewIntent。 如不在栈顶,则新建实例 (每个Task都可以有,且可以有多个,在栈顶时可复用) singleTask 新建一个Task,如果已经有其他的Task并且包含该实例,那就直接调用那个Task的实例。(只有一个Task中会有) singleInstance 新建一个Task,且在该Task中只有它的唯一一个实例。 (只有一个Task会有,且该Task中只有它)
FLAG_ACTIVITY_NEW_TASK 类似singleTask FLAG_ACTIVITY_SINGLE_TOP 类似singleTop FLAG_ACTIVITY_CLEAR_TOP 无对应

 

配两个图,我觉得很清晰:

(1)standard

 

(2)singleTask

可以将TaskA TaskB理解为两个应用,比如TaskA是你当前的应用,TaskB是默认浏览器。

当到了TaskB中后,按返回键,需要先在TaskB中返回到root,然后才能返回到TaskA。

 

 

总结成以下几句

  1. standard  每次都会新建,每个Task都可以有,且每个Task都可以有多个实例(每个Task都可以有,且可以有多个)
  2. singleTop 当前实例如果在栈顶,就不新建实例,调用其OnNewIntent。 如不在栈顶,则新建实例  (每个Task都可以有,且可以有多个,在栈顶时可复用)
  3. singleTask 新建一个Task,如果已经有其他的Task并且包含该实例,那就直接调用那个Task的实例。(只有一个Task中会有)
  4. singleInstance 新建一个Task,且在该Task中只有它的唯一一个实例。 (只有一个Task会有,且该Task中只有它)

standard  每次都会新建,每个Task都可以有,且每个Task都可以有多个实例(每个Task都可以有,且可以有多个)

singleTop 当前实例如果在栈顶,就不新建实例,调用其OnNewIntent。 如不在栈顶,则新建实例  (每个Task都可以有,且可以有多个,在栈顶时可复用)

singleTop 当前实例如果在栈顶,就不新建实例,调用其OnNewIntent。 如不在栈顶,则新建实例  (每个Task都可以有,且可以有多个,在栈顶时可复用)

singleInstance 新建一个Task,且在该Task中只有它的唯一一个实例。 (只有一个Task会有,且该Task中只有它)

 

img

500px: OscillatiOns http://goo.gl/mag/Usfa2

会议室的灯灯很漂亮

image

qq阅读越来越有意思了

http://book.qq.com/s/book/0/25/25064/index.shtml

猴子玩手机

image

好先进

“秋天”的落叶

image

其实不难发现,大多数像法桐这样的植物,秋天叶子其实还是好好的在树上呆着,秋天甚至还有发很多新芽,绿绿葱葱的,也很好看,到了冬天,就都傻眼了,北风一吹就呼啦啦落下来,该干嘛干嘛。
    也很正常,按叶子的理解在树上多舒服,你没落,我为什么先落,其实素不知自己只是树收集养料的道具。
    最傻的只有种子,别人都舒服的呆着,他老人家一个人早早的掉下来,掉进还没结冻的土里,休眠一冬,来年生根发芽。可惜数冠上大多数是叶子,极少种子,大自然真奇妙。

吃面

image

这是英文字母形状的意面,宝宝吃剩的

xMove + MultiBeast: Install OS X 10.7 Lion on any Supported Intel Core 2 or Core i based PC

Any
OSx86 installation guide can seem daunting at first glance, especially
when trying to remember cryptic terminal commands and sorting through
volumes of misinformation on the web. This guide requires no coding,
terminal work, or Mac experience of any kind.
Because
Apple is only distributing OS X Lion through the Mac App Store, we had
to rethink our retail installation method. What follows is our
recommendation for the easiest, cleanest and most Mac-like installation
process. For best results, follow this guide to the letter.
This
guide is for the Retail OS X Lion App downloaded from the Mac App
Store. If you are using the OS X Lion USB Thumb Drive, a new guide is
coming soon. 
You will need: 
A System Running Mac OS X Snow Leopard 10.6.6 or later with:
  • Intel Core 2 or above, 64 bit CPU
  • Mac App Store Account + $29.99
  • Internet Access to Download 4GB OS X Lion App through Mac App Store
  • 4GB space available in /Applications
  • 8GB additional free space on your hard drive
  • Mac Pro 3,1 system definition and the latest Chimera Bootloader from MultiBeast
Don’t have Snow Leopard yet? To install Mac OS X Snow Leopard from the Retail DVD follow iBoot + MultiBeast.
STEP 1: Purchase OS X Lion from the Mac App Store1. Boot into your existing Snow Leopard installation.

2. Download the OS X Lion App directly from the Mac App Store - it will automatically open.

     3. Click Continue.
4. Target your currently booted Snow Leopard drive and hit Install. This will not install the OS or affect this drive in any way. It will simply install the files necessary to do so later in the process. 
     5. Click Restart to reboot.
STEP 2: Prepare the Installer Partition

1. Boot back into your existing Snow Leopard installation.

2. Open /Applications/Utilities/Disk Utility

     3. Highlight your Snow Leopard drive in left column.
     4. Choose the Partition tab, and Click the + to Add a Partition.
     5. Name the secondary partition Installer with a size of 8 GB and click Apply.
     6. Click Partition.
     7. Close Disk Utility
STEP 3: xMove
     1. Download xMove
     2. Double-Click xMove, and choose Installer as Destination.
WARNING: DO NOT choose existing Snow Leopard as the Destination.
Do
not interrupt the process- it will only take a few minutes. When done,
you’ll have a secondary partition on your drive containing the OS X Lion
Installer!
If xMove fails, you haven’t installed the Lion App to your currently booted drive-
and it cannot find the necessary files. A quick way to remedy this is
to manually mount the InstallESD.dmg and run xMove again.
STEP 4: Boot Installer & Install OS X Lion

1. Reboot- at the Chimera boot screen, choose Installer

2. It will boot directly to a familiar Mac OS X Installer complete with Disk Utility.

3. Install OS X Lion over existing Snow Leopard or onto any empty drive or partition.

If you’ve installed directly over an existing Snow Leopard installation,
you’re done! You should already have done proper post-installation
steps on your existing Snow Leopard drive, so skip Step 5 and simply
reboot into Lion!

STEP 5: MultiBeast

MultiBeast is
an all-in-one post-installation tool designed to enable boot from hard
drive, and install support for Audio, Network, and Graphics. It contains
two different complete post-installation solutions: UserDSDT and
EasyBeast. In addition it includes System Utilities to rebuild caches
and repair permissions and a collection of drivers, boot loaders, boot
time config files and handy software.
Choose one of the following options directly following a fresh installation:
UserDSDT is
a bare-minimum solution for those who have their own pre-edited DSDT.
Place your DSDT.aml on the desktop before install. Audio, Graphics and
Network will have to be enabled separately. Check out our DSDT Database to download your motherboard’s pre-edited DSDT.EasyBeast is
a DSDT-free solution for any Core2/Core i system. It installs all of
the essentials to allow your system to boot from the hard drive. Audio,
Graphics and Network will have to be enabled separately.  

1. At Chimera boot screen, choose your freshly installed Lion drive

2. Complete setup and registration routine

3. When you get to the desktop, run MultiBeast

4. If you have a custom pre-edited DSDT, place it on your desktop and choose UserDSDT

     5. All others select EasyBeast6. Select System Utilities

     7. Reboot to OS X Lion
You may also use MultiBeast to install further drivers to enable ethernet, sound, graphics, etc… Be sure to read the documentation provided in MultiBeast Features.pdf about each option. Both UserDSDT and EasyBeast install the proper bootloader by default, so you’ll not need to check that option.8. Optionally, you can now use Disk Utility to delete the Installer partition.

Congratulations!

You now have a fully updated bootable version of OS X Lion on your
CustoMac! If you have any trouble, there are plenty of folks in the
tonymacx86 forum with similar hardware to help out! Special thanks
to all the hard work and effort of everyone involved in the
community, all of our Mods for testing and retesting this method, and
to Adamsmasher and Complx for the new logos!

If you’ve had success using xMove + MultiBeast, consider a contribution to help keep the sites going.  We’re constantly updating and tweaking our tools to help you.

Thanks in advance!

-tonymacx86 & MacMan

Related Posts: 

For discussions on this and other topics, register today at tonymacx86.com!

要好好学学法

image

好好学习,天天向上

Linux下的NTP服务器

NTP(Network Time Protocol)服务器是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正,在LAN上与标准间差小于1毫秒,WAN上几十毫秒,且通过加密确认的方式来防止恶毒的协议攻击。
1)         配置文件
目录名称
应用说明
/etc/ntp.conf
NTP服务的主要配置文件,不同的Linux版本文件所在的目录可能会不同
/usr/share/zoneinfo
规定了各主要时区的时间设定文件,例如中国大陆地区的时区设置文件是/usr/share/zoneinfo/Asia/Shanghai
/etc/sysconfig/clock
Linux的主要时区设定文件。每次启动后Linux操作系统会自动读取这个文件来设定系统预设要显示的时间。如这个文件内容为”ZONE=Asia/Shanghai”,则表示Linux操作系统的时间设定使用/usr/share/zoneinfo/Asia/Shanghai这个文件
/etc/localtime
本地系统的时间设定文件,如果clock文件中规定了使用的时间设定文件为/usr/share/zoneinfo/Asia/Shanghai,Linux操作系统就会将Shanghai那个文件复制一份为/etc/localtime,所以系统的时间显示就会以Shanghai那个时间设定文件为准

 

2)         有关的执行文件
命令名称
应用说明
/bin/date
Linux系统中的修改及输出日期与时间命令
/sbin/hwclock
主机的BIOS时间与Linux系统时间是分开的,所以使用date命令调整时间之后,只是调整了Linux的系统时间。还需要使用hwclock才能将修改过后的时间写入BIOS,这个命令必须root用户才能执行
/usr/sbin/ntpd
NTP服务的守护进程文件,需要启动它才能提供NTP服务
/usr/sbin/ntpdate
NTP客户端用来连接NTP服务器命令文件
/usr/sbin/ntpq
标准的网络计时协议(NTP)查询程序
/usr/sbin/_ntptrace
跟踪网络计时协议主机链到它们的控制时间源
/sbin/clock
调整电脑硬件时间RTC,执行这个命令可以显示现在时刻。调整硬件时钟的时间将系统时间设成与硬件时钟之时间一致,或是把系统时间回存到硬件时钟

说明:Linux时钟系统在分类和设置上与Windows不同的是它将时钟分为系统时钟(System Clock)和硬件时钟(Real Time Clock,RTC)两种,系统时间是指当前Linux Kernel中的时钟;硬件时钟则是主板上由电池供电的主板硬件时钟,这个时钟可以在BIOS中设置。当Linux启动时,硬件时钟会读取系统时钟的设置,然后系统时钟就会独立于硬件运行

3)         重要主配置文件详解

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org

#broadcast 192.168.1.255 key 42         # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 key 42             # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 key 42  # manycast client

manycastclient 239.255.254.254 key 42  # manycast client

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10

# Drift file.  Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()’ing
# it to the file.
driftfile /var/lib/ntp/drift

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

Ø 设定客户端同步规则
l 格式
restrict ip地址 mask子网掩码 参数
其中ip可以为ip地址或default,default指所有ip
l 参数解释(如果未设定参数表示对该IP或子网没有任何限制)
ignore:关闭所有的NTP联机服务
nomodify:客户端不能更改服务端的时间参数,但是可以通过服务端进行网络校时
notrust:客户端除非通过认证,否则其来源将被视为不信任子网
noquery:不提供客户端的时间查询
Ø 设定上级时间服务器
l 格式
Server IP地址或域名 [prefer]
l 参数解释
IP地址或域名为指定的上级时间服务器,如果在Server参数后加上prefer,表示NTP服务器主要以其主机时间校准
Ø 广播时间
l 格式
broadcast 网段
l 解释
ntpd在子网中的网络上定期广播NTP时间,如broadcast 192.168.255.255表示在192.168.0.0/16的网络上定期广播NTP时间
Ø 时间记录
l 格式
driftfile文件名
l 解释
与上级时间服务器联系时所花费的时间记录在driftfile参数后面的文件中,driftfile后面需要使用完整的路径文件名,不能是连接文件,并且文件的权限需要设定为ntpd守护进程且可以写入
Ø 时间级别
l 格式
fudge IP地址 stratum 级别
l 解释
fudge项用于为这个时钟设置级别。对待内部系统时钟的比较理想的情况是将时间源作为级别10来对待,这样访问真正NTP服务器的客户端将与这些服务器同步