假设我有一个名为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?谢谢。
发布于 2019-11-28 01:08:20
很简单。
Intent intent = new Intent(this, TargetActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);这就是你想要的。如果任务堆栈中已经存在TargetActivity的实例,则该实例将被重新排列并移到堆栈的顶部(前面)。如果没有现有的TargetActivity实例,安卓将创建一个新实例并将其放在堆栈的顶部。
https://stackoverflow.com/questions/59045860
复制相似问题