且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

后台运行 程序

更新时间:2022-08-14 22:05:24

项目要求

应用启动时,有A B C 三个ACTIVITY 进到A B C任何一个activity 按下home键,程序在后台运行,当恢复应用的时候,应用显示之前被按下home键的那个页面。

 

可以查到官方文档:

 moveTaskToBack(true);

 

官方给出的说明是:

Move 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.

 也就是说 将包含actvity的任务放到 activity的栈顶,但是在栈任务里面的顺序不会改变

参数说明:

  当值为false的时候,只在当前的activity是栈任务的根才起作用,当值为ture的时候,栈任务里面的任何一个activity都起作用。

返回

    如果任务呗移动的(或者已经在栈顶了),返回ture,否则返回false。