重新开始活动后重置海军图
我有一个带有2个片段的导航图,片段A和片段B。 片段A是我的开始目的地。
如果我在Fragment B中,并且打开应用程序设置,并撤销许可,我会看到:
- 重新创建活动,但是我看不到
ondestory
被调用, - 而不是使用Fragment A启动活动,该活动是从片段开始的。
我还看到该应用程序已重新创建并直接打开活动B,而不是从活动A开始(旧代码,我们几乎没有活动)
可以以某种方式重置导航图,以便它会以某种方式重置从碎片开始?
谢谢。
I've a navigation graph with 2 fragments, Fragment A and Fragment B.
Fragment A is my start destination.
If I'm in Fragment B and I open the app settings, and revoke a permission I see that:
- activity is recreated, but I don't see
onDestory
is called - instead of starting the activity with Fragment A, the activity is started with Fragment B.
I also see that the application is recreated and opens directly Activity B instead of starting from Activity A (old code, we have few activities)
is there a way to reset the navigation graph somehow so it will start from Fragment A?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
遇到您的问题,寻找类似问题的答案。
就我而言,我有一个单一的活动应用程序,该应用在更改许可状态时在片段B中,并且在重新启动活动后,在片段B中重新打开。像您一样,我希望我的活动从片段A开始,这也是我的NAV图的开始或默认目的地。
我解决的问题的方法是,由于
conical_permission_change
,我都会检测到,然后我将savedinstancestate
内部无效。我的活动的oncreate()
。这里有一些代码:
这可能是一种黑客,但是这个小技巧可能会帮助您为特定问题提供更合适的解决方案。只要您从给定的活动中摆脱
SAVEDINSTANCESTATE
,您就应该能够按照期望它的方式重新启动 RESTART 。Ran into your question looking for an answer for a similar problem.
In my case, I have a single Activity app which is in Fragment B when the permission state is changed, and also reopens in Fragment B after the Activity is restarted. Like you, I want my Activity to start with Fragment A, which is also the start or default destination of my nav graph.
The way I solved my problem was that, I would detect whenever the Activity had been exited because of a
REASON_PERMISSION_CHANGE
, then I nullify thesavedInstanceState
inside my Activity'sonCreate()
.Here's some code:
It might be kind of a hack, but this little trick might help you arrive at a more fitting solution for your particular problem. As long as you get rid of the
savedInstanceState
from the given Activity when it matters, you should be able to restart your Activity the way you would expect it to do so.当活动将重新创建活动时,此代码将重置NAV图。
This code will reset nav graph when the activity will recreate.
我最终这样做:
在on Create中:
I ended up doing it this way:
in onCreate: