FLAG_ACTIVITY_TASK_ON_HOME :把当前新启动的任务置于Home任务之上,也就是按back键从这个任务返回的时候会回到home,即使这个不是他们最后看见的activity

注意这个标记必须和FLAG_ACTIVITY_NEW_TASK一起使用。

实例:

一个apk中有MainActivity,ActivityA,点击MainActivity启动ActivityA,

    public void onClick(View arg0) {  
        // TODO Auto-generated method stub  
        Log.i(TAG, "--onClick--task id = " + getCurrentTaskId());  
        Intent intent = new Intent("com.leaves.ipanel.ActivityA");      
        intent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME | Intent.FLAG_ACTIVITY_NEW_TASK);  
        startActivity(intent);   
    }  


启动后的堆栈:
    ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)  
      Main stack:  
        TaskRecord{43bb4e48 #7 A com.leaves.ipanel.ActivityA U 0}     Intent { act=com.leaves.ipanel.ActivityA flg=0x10004000 cmp=com.leaves.ipanel/.ActivityA }  
          Hist #2: ActivityRecord{4274a5c0 u0 com.leaves.ipanel/.ActivityA}  
            Intent { act=com.leaves.ipanel.ActivityA flg=0x10004000 cmp=com.leaves.ipanel/.ActivityA }  
            ProcessRecord{4267a850 1924:com.leaves.ipanel/u0a10061}  
        TaskRecord{426f4820 #2 A com.android.launcher U 0}  
        Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10600000 cmp=com.android.launcher/com.android.launcher2.Launcher }  
          Hist #1: ActivityRecord{4291c7b0 u0 com.android.launcher/com.android.launcher2.Launcher}  
            Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher/com.android.launcher2.Launcher }  
            ProcessRecord{4267f0b8 636:com.android.launcher/1000}  
        TaskRecord{4360ab48 #5 A com.leaves.ipanel U 0}  
        Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.leaves.ipanel/.MainActivity bnds=[163,708][307,852] }  
          Hist #0: ActivityRecord{426b6380 u0 com.leaves.ipanel/.MainActivity}  
            Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.leaves.ipanel/.MainActivity bnds=[163,708][307,852] }  
            ProcessRecord{4267a850 1924:com.leaves.ipanel/u0a10061}  

堆栈信息中我们可以看出,ActivityA位于了Launcher即Home之上,而MainActivity被移动到了后台,所以这个时候我们按返回键,将返回到Home,而不是MainActivity