您的位置:首页 > 其它

Activity之isTaskRoot和moveTaskToBack方法简介

2016-05-06 18:57 435 查看
1、public boolean isTaskRoot()用来判断该Activity是否为任务栈中的根Activity,即启动应用的第一个Activity

2、public boolean moveTaskToBack (boolean
nonRoot)用于将activity退到后台,不是finish

从生命周期来说,会执行onPause、onStop,但不会执行onDestroy

恢复的时候也一样,会执行onStart、onResume,但不会执行onCreate

参数nonRoot表示的含义是此方法对非根activity是否有效,也就是说true表示对所有activity均有效,false表示只对根activity有效。

返回值:该activity被退出到后台或者他已经在后台了返回true,否则返回false

官方文档:

public boolean moveTaskToBack (boolean nonRoot)

Since: API Level 1Move the task containing this activity to the back of the activity stack. The activity's order within the task is unchanged.

Parameters

nonRoot If false then this only works if the activity is the root of a task; if true it will work for any activity in a task.

Returns

If the task was moved (or it was already at the back) true is returned, else false.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: