Xamarin Forms - Duplicate Screens












0















I'm writing an app using Xamarin Forms and I have an issue I was hoping someone can help with.



My app contains a screen which has multiple icons that can be pressed which would then open a new screen.



My issue is that if you press the icon twice really fast, the app opens up 2 instances of the same screen (it's not just related to a double press, if you press the icon 6 times very fast it will open up 6 duplicate screens). Pressing the Back button, closes the top screen to reveal the duplicate screen underneath. Pressing the Back button again navigates you back to the original screen.



This issue seems to occur on any screen within my app so I'm hoping other people will have experienced it and know of a solution to prevent duplicate screens being displayed.










share|improve this question



























    0















    I'm writing an app using Xamarin Forms and I have an issue I was hoping someone can help with.



    My app contains a screen which has multiple icons that can be pressed which would then open a new screen.



    My issue is that if you press the icon twice really fast, the app opens up 2 instances of the same screen (it's not just related to a double press, if you press the icon 6 times very fast it will open up 6 duplicate screens). Pressing the Back button, closes the top screen to reveal the duplicate screen underneath. Pressing the Back button again navigates you back to the original screen.



    This issue seems to occur on any screen within my app so I'm hoping other people will have experienced it and know of a solution to prevent duplicate screens being displayed.










    share|improve this question

























      0












      0








      0








      I'm writing an app using Xamarin Forms and I have an issue I was hoping someone can help with.



      My app contains a screen which has multiple icons that can be pressed which would then open a new screen.



      My issue is that if you press the icon twice really fast, the app opens up 2 instances of the same screen (it's not just related to a double press, if you press the icon 6 times very fast it will open up 6 duplicate screens). Pressing the Back button, closes the top screen to reveal the duplicate screen underneath. Pressing the Back button again navigates you back to the original screen.



      This issue seems to occur on any screen within my app so I'm hoping other people will have experienced it and know of a solution to prevent duplicate screens being displayed.










      share|improve this question














      I'm writing an app using Xamarin Forms and I have an issue I was hoping someone can help with.



      My app contains a screen which has multiple icons that can be pressed which would then open a new screen.



      My issue is that if you press the icon twice really fast, the app opens up 2 instances of the same screen (it's not just related to a double press, if you press the icon 6 times very fast it will open up 6 duplicate screens). Pressing the Back button, closes the top screen to reveal the duplicate screen underneath. Pressing the Back button again navigates you back to the original screen.



      This issue seems to occur on any screen within my app so I'm hoping other people will have experienced it and know of a solution to prevent duplicate screens being displayed.







      xamarin.forms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 14:51









      plingingoplingingo

      286




      286
























          3 Answers
          3






          active

          oldest

          votes


















          0














          This is a known issue in TapEvents.



          My hack is, in the code-behind, have a bool variable _canTap.



          Inside the method you are calling to push new page, first you check if canTap, then set to false, and only set to true after navigating to another page. This way all taps will be disregarded.



          Example:



           private bool _canTap = true;


          public void YourMethod()
          {
          if(_canTap)
          {
          _canTap = false;
          YourMethodToNavigate();
          _canTap = true;
          }
          }





          share|improve this answer































            0














            In the Icon_Pressed method add this,



            this.IsEnabled = false;

            await Navigation.PushAsync(new MyPage());

            this.IsEnabled = true;


            It disables the page until the current Icon pressed event is finished






            share|improve this answer































              0














              This is known problem with Xamarin apps. I've used a private variable combined with a try-finally pattern to solve this. Ex:



              bool allowTap = true;

              public void ButtonTapped()
              {
              try
              {
              if(allowTap)
              {
              allowTap = false;
              // Do whatever...
              }
              }
              finally
              {
              allowTap = true;
              }
              }


              The finally makes sure allowTap gets set back to true no matter what happens, short of a complete crash. Note that you can also use a catch block between the try and finally blocks to grab any errors if needed.






              share|improve this answer























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448828%2fxamarin-forms-duplicate-screens%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                0














                This is a known issue in TapEvents.



                My hack is, in the code-behind, have a bool variable _canTap.



                Inside the method you are calling to push new page, first you check if canTap, then set to false, and only set to true after navigating to another page. This way all taps will be disregarded.



                Example:



                 private bool _canTap = true;


                public void YourMethod()
                {
                if(_canTap)
                {
                _canTap = false;
                YourMethodToNavigate();
                _canTap = true;
                }
                }





                share|improve this answer




























                  0














                  This is a known issue in TapEvents.



                  My hack is, in the code-behind, have a bool variable _canTap.



                  Inside the method you are calling to push new page, first you check if canTap, then set to false, and only set to true after navigating to another page. This way all taps will be disregarded.



                  Example:



                   private bool _canTap = true;


                  public void YourMethod()
                  {
                  if(_canTap)
                  {
                  _canTap = false;
                  YourMethodToNavigate();
                  _canTap = true;
                  }
                  }





                  share|improve this answer


























                    0












                    0








                    0







                    This is a known issue in TapEvents.



                    My hack is, in the code-behind, have a bool variable _canTap.



                    Inside the method you are calling to push new page, first you check if canTap, then set to false, and only set to true after navigating to another page. This way all taps will be disregarded.



                    Example:



                     private bool _canTap = true;


                    public void YourMethod()
                    {
                    if(_canTap)
                    {
                    _canTap = false;
                    YourMethodToNavigate();
                    _canTap = true;
                    }
                    }





                    share|improve this answer













                    This is a known issue in TapEvents.



                    My hack is, in the code-behind, have a bool variable _canTap.



                    Inside the method you are calling to push new page, first you check if canTap, then set to false, and only set to true after navigating to another page. This way all taps will be disregarded.



                    Example:



                     private bool _canTap = true;


                    public void YourMethod()
                    {
                    if(_canTap)
                    {
                    _canTap = false;
                    YourMethodToNavigate();
                    _canTap = true;
                    }
                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 23 '18 at 16:00









                    Bruno CaceiroBruno Caceiro

                    3,49111330




                    3,49111330

























                        0














                        In the Icon_Pressed method add this,



                        this.IsEnabled = false;

                        await Navigation.PushAsync(new MyPage());

                        this.IsEnabled = true;


                        It disables the page until the current Icon pressed event is finished






                        share|improve this answer




























                          0














                          In the Icon_Pressed method add this,



                          this.IsEnabled = false;

                          await Navigation.PushAsync(new MyPage());

                          this.IsEnabled = true;


                          It disables the page until the current Icon pressed event is finished






                          share|improve this answer


























                            0












                            0








                            0







                            In the Icon_Pressed method add this,



                            this.IsEnabled = false;

                            await Navigation.PushAsync(new MyPage());

                            this.IsEnabled = true;


                            It disables the page until the current Icon pressed event is finished






                            share|improve this answer













                            In the Icon_Pressed method add this,



                            this.IsEnabled = false;

                            await Navigation.PushAsync(new MyPage());

                            this.IsEnabled = true;


                            It disables the page until the current Icon pressed event is finished







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 23 '18 at 16:05









                            PrateekPrateek

                            2,40141435




                            2,40141435























                                0














                                This is known problem with Xamarin apps. I've used a private variable combined with a try-finally pattern to solve this. Ex:



                                bool allowTap = true;

                                public void ButtonTapped()
                                {
                                try
                                {
                                if(allowTap)
                                {
                                allowTap = false;
                                // Do whatever...
                                }
                                }
                                finally
                                {
                                allowTap = true;
                                }
                                }


                                The finally makes sure allowTap gets set back to true no matter what happens, short of a complete crash. Note that you can also use a catch block between the try and finally blocks to grab any errors if needed.






                                share|improve this answer




























                                  0














                                  This is known problem with Xamarin apps. I've used a private variable combined with a try-finally pattern to solve this. Ex:



                                  bool allowTap = true;

                                  public void ButtonTapped()
                                  {
                                  try
                                  {
                                  if(allowTap)
                                  {
                                  allowTap = false;
                                  // Do whatever...
                                  }
                                  }
                                  finally
                                  {
                                  allowTap = true;
                                  }
                                  }


                                  The finally makes sure allowTap gets set back to true no matter what happens, short of a complete crash. Note that you can also use a catch block between the try and finally blocks to grab any errors if needed.






                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    This is known problem with Xamarin apps. I've used a private variable combined with a try-finally pattern to solve this. Ex:



                                    bool allowTap = true;

                                    public void ButtonTapped()
                                    {
                                    try
                                    {
                                    if(allowTap)
                                    {
                                    allowTap = false;
                                    // Do whatever...
                                    }
                                    }
                                    finally
                                    {
                                    allowTap = true;
                                    }
                                    }


                                    The finally makes sure allowTap gets set back to true no matter what happens, short of a complete crash. Note that you can also use a catch block between the try and finally blocks to grab any errors if needed.






                                    share|improve this answer













                                    This is known problem with Xamarin apps. I've used a private variable combined with a try-finally pattern to solve this. Ex:



                                    bool allowTap = true;

                                    public void ButtonTapped()
                                    {
                                    try
                                    {
                                    if(allowTap)
                                    {
                                    allowTap = false;
                                    // Do whatever...
                                    }
                                    }
                                    finally
                                    {
                                    allowTap = true;
                                    }
                                    }


                                    The finally makes sure allowTap gets set back to true no matter what happens, short of a complete crash. Note that you can also use a catch block between the try and finally blocks to grab any errors if needed.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 25 '18 at 21:55









                                    AndrewAndrew

                                    42719




                                    42719






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448828%2fxamarin-forms-duplicate-screens%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Wiesbaden

                                        To store a contact into the json file from server.js file using a class in NodeJS

                                        Marschland