如何调出Android中活动后台堆栈中存在的活动?



假设我有一个名为ActivityA的活动和另一个名为ActivityB的活动。在每个按钮中,我都有一个按钮,单击时会打开另一个活动。单击按钮时,我想做以下工作:

check if there is an existing type of the target Activity in the activity back-stack or not, if there is, bring that Activity to the top and if not create new Intent and then go to that Activity.
How can I implement this?

谢谢。

很简单。

Intent intent = new Intent(this, TargetActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

这完全符合您的要求。如果任务堆栈中已经存在TargetActivity实例,则该实例将被重新排列并带到堆栈的顶部(前面(。如果没有现有的TargetActivity实例,Android将创建一个新实例并将其放在堆栈的顶部。

相关内容

最新更新