我正在使用标志 FLAG_ACTIVITY_SINGLE_TOP
和 FLAG_ACTIVITY_CLEAR_TOP
返回我之前的“标准” Activity 。我使用 FLAG_ACTIVITY_SINGLE_TOP
来防止重新创建新实例。但我发现标志 FLAG_ACTIVITY_SINGLE_TOP
被忽略, Activity 完成并重新创建。
这是我在文档中找到的内容。 FLAG_ACTIVITY_CLEAR_TOP :它说您可以在使用
FLAG_ACTIVITY_CLEAR_TOP
时添加FLAG_ACTIVITY_SINGLE_TOP
以防止“完成 - 重新创建”。这是另一个文档。 FLAG_ACTIVITY_CLEAR_TOP :
Note: If the launch mode of the designated activity is "standard", it too is removed from the stack and a new instance is launched in its place to handle the incoming intent. That's because a new instance is always created for a new intent when the launch mode is "standard".
我误解了第一个文档吗?
最佳答案
文档表明您只需设置 FLAG_ACTIVITY_CLEAR_TOP。但实际上您必须同时设置两者以防止再次创建 Activity 。
这在我的案例中起到了作用:(主要是我想返回的 Activity )
Intent tabIntent = new Intent(this, Main.class);
tabIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(tabIntent);
关于android - 不能在一个 Intent 中同时设置 FLAG_ACTIVITY_SINGLE_TOP 和 FLAG_ACTIVITY_CLEAR_TOP 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5622365/