[英]Navigating through multiple activities
I have 2 Activities A and B . 我有2个活动A和B。 Now these are my objectives.
现在这些是我的目标。
But in Step 2 the state of B still prevails. 但是在步骤2中,状态B仍然有效。 How do I accomplish my objective?
我如何实现我的目标?
I think one possible solution woudl be to pass some extra information inside the starting Intent, when you start Activity B from A (like a boolean value). 我认为一种可行的解决方案是,当您从A启动Activity B时,在启动Intent内传递一些额外的信息(如布尔值)。 And in the "onStart()" of B, you check if you can find this extra info in the intent (you get it with getIntent()).
然后在B的“ onStart()”中,检查是否可以在意图中找到此额外信息(您可以通过getIntent()获得它)。 If it's not present, that means you do reload the activity's previous state.
如果不存在,则表示您确实要重新加载活动的先前状态。 If it is, then you don't reload it.
如果是这样,则您无需重新加载它。
You don't even need to send a boolean like Scythe suggested. 您甚至不需要发送像Scythe建议的布尔值。 The
Bundle savedInstanceState
will be null in onCreate
for Activity B if Activity A just started it, whereas it will be non-null if you are coming back from a saved state. 如果活动A刚刚开始,则在活动B的
onCreate
Bundle savedInstanceState
将为null,而如果您从已保存状态返回,则该Bundle savedInstanceState
将为非null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.