android - 使用 Intents 时回栈不断添加
问题描述
我有一个活动 A,它使用具有列表的片段 A。活动 A 可以调用搜索活动。我看到的问题是,如果我要进行搜索活动,然后返回活动 A,则从那里加载片段 A。如果我从片段 A 中选择一个项目,我会被带到片段 B,如果我要按下后退按钮,我必须单击它 2 或 3 次。有任何想法吗?我是否需要使用参数启动搜索活动,以便它不会添加到后台堆栈。我在开始搜索活动时尝试了 Intent.FLAG_ACTIVITY_CLEAR_TOP 的标志,但出现了问题。
爪哇:
活动一:
public void popFragment(){
if(getSupportFragmentManager().getBackStackEntryCount() > 1) {
getSupportFragmentManager().popBackStack();
getSupportFragmentManager().executePendingTransactions();
}
}
片段 A:
private void showSearchActivity(){
Intent intent = new Intent(context, SearchActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent, 0)
}
解决方案
推荐阅读
- git - Unity 2019 中软件包的版本控制
- nlp - 如何从词嵌入中恢复某个词出现在给定上下文中的可能性?
- javascript - .map() 参数未定义
- opencv - OpenCV dnn、OpenCL 和 Nvidia 显卡
- php - 对表上的 PHP/SQL 删除没有影响
- spring-boot - 如何将 p12 客户端证书与 spring feign 客户端一起使用
- c# - 使用 AJAX 传递模型和变量
- rest - 如何在 Jenkins 中通过 REST 更新 nextBuildNumber
- ruby-on-rails - 对 Shopify 应用进行身份验证 - 缺少“代码”参数
- pyspark - SparkSQL(Databricks):将数据插入到由不同角色创建的雪花表中