去哪儿 Android App怎么实现退出后不留在最近运行任务栏的?

关注者
52
被浏览
9,920
登录后你可以
不限量看优质回答私信答主深度交流精彩内容一键收藏

这个只要给Activity设置“android:excludeFromRecents=true”即可,官方的解释如下:

android:excludeFromRecentsWhether or not the task initiated by this activity should be excluded from the list of recently used applications, the overview screen. That is, when this activity is the root activity of a new task, this attribute determines whether the task should not appear in the list of recent apps. Set "true" if the task should be excluded from the list; set "false" if it should be included. The default value is "false".

如果设置为true,那么这个Activity将不会出现在最近任务列表中,如果这个Activity是整个Task的根Activity,整个Task将不会出现在最近任务列表中。

同样,也可以通过Intent的启动,并设置 Flag: “FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS”,Flag 值为 “0x00800000”,参考

Intent | Android Developers

在退出哪儿App时候,查看一下 ActivityManager 的 log,如下:

I/ActivityManager﹕ START u0 {flg=0x14818000 cmp=com.Qunar/com.mqunar.atom.alexhome.ui.activity.MainActivity (has extras)}

可见,在退出的时候,启动了一个Activity,注意这里的 flg=0x14818000,可见 “FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS” 的 flag 被设置了。也就是启动了一个不显示在最近任务列表中的新Activity。这就达到了那个退出App,不显示在最近任务列表的效果。

不过我比较大胆的猜测一下,本App让它不出现在最近任务列表中,让用户感觉就像没有打开一样,似乎并不占用系统资源,可能是想通过这个方法来逃避被杀掉。然而,这并没有什么太大用处,如果用户点击清除内存(很多系统或者xx卫士、xx管家都有这样的功能),照样会被干掉。

最后吐槽一下,去哪儿App的包名中竟然有大写字符。