8

Activity的四种启动模式-图文并茂

 3 years ago
source link: http://www.androidchina.net/3173.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Activity的四种启动模式-图文并茂 – Android开发中文站
你的位置:Android开发中文站 > Android开发 > 新手入门 > Activity的四种启动模式-图文并茂
1、对于使用standard 模式的活动,系统不会在乎这个活动是否已经在返回栈中存在,每次启动都会创建该活动的一个新的实例。
例如A启动A,A再接着启动A,A继续启动A,然后再分别出栈,如图所示
20150725145328561
2、当活动的启动模式指定为 singleTop,在启动活动时如果发现返回栈的栈顶已经是该活动,则认为可以直接使用它,不会再创建新的活动实例。
20150725145859995
3、当活动的启动模式指定为 singleTask,每次启动该活动时系统首先会在返回栈中检查是否存在该活动的实例,如果发现已经存在则直接使用该实例,并把在这个活动之上的所有活动统统出栈,如果没有发现就会创建一个新的活动实例。
20150725150520686
4、使用singleInstance 模式就可以解决这个问题,在这种模式下会有一个单独的返回栈来管理这个活动,不管是哪个应用程序来访问这个活动,都共用的同一个返回栈,也就解决了共享活动实例的问题。
假设B启动A,A启动C,其中A的启动模式为singleInstance,则:
20150725151057456
返回的页面顺序是C-B-A

转载请注明:Android开发中文站 » Activity的四种启动模式-图文并茂


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK