Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android避免在将任务放在最前面时启动新活动_Android_Android Activity_Back Stack - Fatal编程技术网

Android避免在将任务放在最前面时启动新活动

Android避免在将任务放在最前面时启动新活动,android,android-activity,back-stack,Android,Android Activity,Back Stack,我有一个启动器活动a,它立即启动第二个活动B并完成。活动B然后启动活动C并完成。 所以backback现在只包含活动C。 当用户按下home按钮并重新启动应用程序(通过单击图标)而不是将C带到前面时,启动程序活动A被调用。堆栈现在变成C->A。A立即启动B,最后的堆栈看起来是C->B 我只想恢复活动C。我已经阅读了tasks and back stack guide,但不确定要使用哪个标志。感谢您的帮助 编辑:在启动活动时,清单或意图标志中没有任何启动模式标志。请使用此代码 @Override

我有一个启动器活动a,它立即启动第二个活动B并完成。活动B然后启动活动C并完成。 所以backback现在只包含活动C。 当用户按下home按钮并重新启动应用程序(通过单击图标)而不是将C带到前面时,启动程序活动A被调用。堆栈现在变成C->A。A立即启动B,最后的堆栈看起来是C->B

我只想恢复活动C。我已经阅读了tasks and back stack guide,但不确定要使用哪个标志。感谢您的帮助


编辑:在启动活动时,清单或意图标志中没有任何启动模式标志。

请使用此代码

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { 
        // Activity was brought to front and not created, 
        // Thus finishing this will get us to the last viewed activity 
        finish(); 
        return; 
    } 

    // Regular activity creation code... 
} 

此代码始终使应用程序打开您离开的最后一个活动使用此代码

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { 
        // Activity was brought to front and not created, 
        // Thus finishing this will get us to the last viewed activity 
        finish(); 
        return; 
    } 

    // Regular activity creation code... 
} 

此代码始终使应用程序打开您离开的最后一个活动使用此代码

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { 
        // Activity was brought to front and not created, 
        // Thus finishing this will get us to the last viewed activity 
        finish(); 
        return; 
    } 

    // Regular activity creation code... 
} 

此代码始终使应用程序打开您离开的最后一个活动使用此代码

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { 
        // Activity was brought to front and not created, 
        // Thus finishing this will get us to the last viewed activity 
        finish(); 
        return; 
    } 

    // Regular activity creation code... 
} 

此代码始终使应用程序打开您离开的最后一个活动

感谢您的快速响应,但根据,当使用标准启动模式时,未设置标志“活动带到前方”。或者是?在哪项活动中?在每项活动中?感谢您的快速响应,但根据,在使用标准启动模式时,未设置将活动带到前方的标志。或者是?在哪项活动中?在每项活动中?感谢您的快速响应,但根据,在使用标准启动模式时,未设置将活动带到前方的标志。或者是?在哪项活动中?在每项活动中?感谢您的快速响应,但根据,在使用标准启动模式时,未设置将活动带到前方的标志。或者是?在哪项活动中?在每项活动中?在启动B和C时,是否有意使用FLAG_ACTIVITY_NEW_TASK?或者您的活动是否在清单中将singleTask作为启动模式?在启动B和C时是否有意使用FLAG_ACTIVITY_NEW_TASK?或者您的活动是否在清单中将singleTask作为启动模式?在启动B和C时是否有意使用FLAG_ACTIVITY_NEW_TASK?或者您的活动是否在清单中将singleTask作为启动模式?在启动B和C时是否有意使用FLAG_ACTIVITY_NEW_TASK?或者您的活动是否在清单中将singleTask作为启动模式?