机器人从BackStack删除片段和查看 [英] Android Remove Fragment and View from BackStack

查看:109
本文介绍了机器人从BackStack删除片段和查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到这个问题已经被问然而,previous答案已经变得我至今之前。该方案如下:我们有一个仪表盘碎片(A),从而导致用户在登录屏幕(B)。成功登录后,他们去一个列表视图(C)。背面preSS我想回归A,因为用户不需要再次看到登录界面。另外在成功登录我们存放在共享preferences的详细信息,并自动登录B中接下来的时间,按计划,所有的作品。

I realise this question has been asked before however the previous answers have gotten me so far. The scenario is as follows: we have a dashboard fragment (A), which leads a user to a login screen (B). On successful login they go to a listview (c). On backpress I would like to return to A, as the user will not need to see the login screen again. In addition on successful login we store the details in shared preferences and automate the login in B next time, which all works as planned.

我有以下FragmentHelper方式:

I have the following FragmentHelper method:

public static void goToNextFragement(Fragment fragment, int container, boolean addToBackStack, Fragment ctx)
    {
        // Create new fragment and transaction
        FragmentTransaction transaction = ctx.getSupportFragmentManager().beginTransaction();
        transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack
        transaction.replace(container, fragment);

        if(addToBackStack)
            transaction.addToBackStack(null);

        // Commit the transaction
        transaction.commit();
    }

在从B到CI交易设置布尔addToBackStack为false,这样 transaction.addToBackStack(空); 不叫。这再一次效果很好,但之后我的问题开始的地方。

In the transaction from B to C I set the Boolean addToBackStack as false so that the transaction.addToBackStack(null); is not called. This again works well but after is where my problem starts.

当用户presses回到C和回报AI还能看到视野下的C的放大视图。

When the user presses back on C and returns to A I can still see the inflated view of C under the view of A.

任何帮助将是AP preciated。我希望我的图有助于保持这一简单。

Any help would be appreciated. I hope my diagram helps keep this simple.

推荐答案

情侣的方式来处理这个问题:

Couple of ways to handle this:

  1. 我有一个类似流在我的应用程序,我解决了它是通过与上来自主要活动开了AlertDialog更换登录片段的方式。 因此,在你的情况下,碎片中的屏幕上显示的,如果主要活动认为它需要显示的登录对话框,它显示AlertDialog。这为我工作。

  1. I had a similar flow in my app and the way I solved it was by replacing the login fragment with a AlertDialog that's fired from the main activity. So in your case, fragment A shows up on screen and if the main activity thinks it needs to show the login dialog, it shows the AlertDialog. This worked for me.

在碎片A被启用时,它可以检查是否片段C是围绕通过询问FragmentManager。如果它存在,然后将其删除。

When fragment A is enabled, it can check if fragment C is around by asking the FragmentManager. If it exists then remove it.

这篇关于机器人从BackStack删除片段和查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆