简体   繁体   English

如何在不恢复的情况下从backstack弹出片段?

[英]How can I pop fragment from backstack without resuming it?

How can I pop fragment from backstack without resuming it? 如何在不恢复的情况下从backstack弹出片段? I just want to remove from back stack, I don't want to display it. 我只想从后台删除,我不想显示它。

If you don't use a FragmentTransaction's method 如果您不使用FragmentTransaction的方法
public abstract FragmentTransaction addToBackStack (String name)
to add it to the back stack. 将其添加到后台堆栈。 There will not be a need to remove it. 没有必要删除它。

It's architectural question. 这是架构问题。

1)Suppose we have 2 controllers (fragments/activities): controller A and controller B. Both of them connected to one instance of some Model (you may use binding with service, Singleton pattern or init model in Application-heir class and make a getter to it). 1)假设我们有2个控制器(片段/活动):控制器A和控制器B.它们都连接到某个模型的一个实例(你可以在Application-heir类中使用绑定服务,单例模式或init模型并制作一个得到它)。 When something interesting happens in controller B, he notifies model about it and then model calls controllerA.finish() / controllerA.remove(). 当控制器B中发生一些有趣的事情时,他会通知模型,然后模型调用controllerA.finish()/ controllerA.remove()。 Of course, I always try to implement this solution as nicely as possible, but there is a main idea. 当然,我总是尝试尽可能好地实现这个解决方案,但有一个主要的想法。

2)In another circumstances, I call finish() immediately after startActivity(intent); 2)在另一种情况下,我在startActivity(intent)之后立即调用finish();

3)Also I may write: startActivityForResult(intent, requestCode) and after finishing second activity method onActivityResult(requestCode, responseCode, intent) is called - if requestCode's are equal, I finish the activity. 3)我也可以写:startActivityForResult(intent,requestCode)和完成第二个活动方法后调用onActivityResult(requestCode,responseCode,intent) - 如果requestCode相等,我完成了活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM