Can I place a MessageCenter subscribe in tabbed paged that are only ever constructed in an application?










1














My application consists of five tabbed pages and nothing else. When it starts all of those tab pages are constructed and they remain that way until the application exits:



 public partial class MainPage : TabbedPage

public MainPage()

InitializeComponent();

App.cardsPage = new DictionaryTab();
App.homePage = new HomePage();
App.helpPage = new HelpPage();
App.settingsPage = new SettingsPage();
App.phrasesPage = new PhrasesFrame(this);

App.navHomePage = new NavigationPage(App.homePage);
App.navHelpPage = new NavigationPage(App.helpPage);
App.navSettingsPage = new NavigationPage(App.settingsPage);
App.navCardsPage = new NavigationPage(App.cardsPage);
App.navPhrasesFrame = new NavigationPage(App.phrasesPage);

Children.Add(App.navHomePage);
Children.Add(App.navHelpPage);
Children.Add(App.navSettingsPage);
Children.Add(App.navCardsPage);
Children.Add(App.navPhrasesFrame);



In the constructors of four of the pages I am subscribing to a MessageCenter message. From what I observe these constructors are run only one time during the lifetime of the application.



It's my understanding that this is not the normal practice but in this case it allows me to update the pages so the results are immediately available when the pages are viewed later.



In this and only this case I would like to find out if it will be a problem. I understand that if the pages were constructed many times it could lead to many issues such as multiple subscriptions, memory problems etc, but in the case where they are tabbed pages that are opened just one time when the applications starts. Would that be a problem and if so what would the problem be?










share|improve this question


























    1














    My application consists of five tabbed pages and nothing else. When it starts all of those tab pages are constructed and they remain that way until the application exits:



     public partial class MainPage : TabbedPage

    public MainPage()

    InitializeComponent();

    App.cardsPage = new DictionaryTab();
    App.homePage = new HomePage();
    App.helpPage = new HelpPage();
    App.settingsPage = new SettingsPage();
    App.phrasesPage = new PhrasesFrame(this);

    App.navHomePage = new NavigationPage(App.homePage);
    App.navHelpPage = new NavigationPage(App.helpPage);
    App.navSettingsPage = new NavigationPage(App.settingsPage);
    App.navCardsPage = new NavigationPage(App.cardsPage);
    App.navPhrasesFrame = new NavigationPage(App.phrasesPage);

    Children.Add(App.navHomePage);
    Children.Add(App.navHelpPage);
    Children.Add(App.navSettingsPage);
    Children.Add(App.navCardsPage);
    Children.Add(App.navPhrasesFrame);



    In the constructors of four of the pages I am subscribing to a MessageCenter message. From what I observe these constructors are run only one time during the lifetime of the application.



    It's my understanding that this is not the normal practice but in this case it allows me to update the pages so the results are immediately available when the pages are viewed later.



    In this and only this case I would like to find out if it will be a problem. I understand that if the pages were constructed many times it could lead to many issues such as multiple subscriptions, memory problems etc, but in the case where they are tabbed pages that are opened just one time when the applications starts. Would that be a problem and if so what would the problem be?










    share|improve this question
























      1












      1








      1







      My application consists of five tabbed pages and nothing else. When it starts all of those tab pages are constructed and they remain that way until the application exits:



       public partial class MainPage : TabbedPage

      public MainPage()

      InitializeComponent();

      App.cardsPage = new DictionaryTab();
      App.homePage = new HomePage();
      App.helpPage = new HelpPage();
      App.settingsPage = new SettingsPage();
      App.phrasesPage = new PhrasesFrame(this);

      App.navHomePage = new NavigationPage(App.homePage);
      App.navHelpPage = new NavigationPage(App.helpPage);
      App.navSettingsPage = new NavigationPage(App.settingsPage);
      App.navCardsPage = new NavigationPage(App.cardsPage);
      App.navPhrasesFrame = new NavigationPage(App.phrasesPage);

      Children.Add(App.navHomePage);
      Children.Add(App.navHelpPage);
      Children.Add(App.navSettingsPage);
      Children.Add(App.navCardsPage);
      Children.Add(App.navPhrasesFrame);



      In the constructors of four of the pages I am subscribing to a MessageCenter message. From what I observe these constructors are run only one time during the lifetime of the application.



      It's my understanding that this is not the normal practice but in this case it allows me to update the pages so the results are immediately available when the pages are viewed later.



      In this and only this case I would like to find out if it will be a problem. I understand that if the pages were constructed many times it could lead to many issues such as multiple subscriptions, memory problems etc, but in the case where they are tabbed pages that are opened just one time when the applications starts. Would that be a problem and if so what would the problem be?










      share|improve this question













      My application consists of five tabbed pages and nothing else. When it starts all of those tab pages are constructed and they remain that way until the application exits:



       public partial class MainPage : TabbedPage

      public MainPage()

      InitializeComponent();

      App.cardsPage = new DictionaryTab();
      App.homePage = new HomePage();
      App.helpPage = new HelpPage();
      App.settingsPage = new SettingsPage();
      App.phrasesPage = new PhrasesFrame(this);

      App.navHomePage = new NavigationPage(App.homePage);
      App.navHelpPage = new NavigationPage(App.helpPage);
      App.navSettingsPage = new NavigationPage(App.settingsPage);
      App.navCardsPage = new NavigationPage(App.cardsPage);
      App.navPhrasesFrame = new NavigationPage(App.phrasesPage);

      Children.Add(App.navHomePage);
      Children.Add(App.navHelpPage);
      Children.Add(App.navSettingsPage);
      Children.Add(App.navCardsPage);
      Children.Add(App.navPhrasesFrame);



      In the constructors of four of the pages I am subscribing to a MessageCenter message. From what I observe these constructors are run only one time during the lifetime of the application.



      It's my understanding that this is not the normal practice but in this case it allows me to update the pages so the results are immediately available when the pages are viewed later.



      In this and only this case I would like to find out if it will be a problem. I understand that if the pages were constructed many times it could lead to many issues such as multiple subscriptions, memory problems etc, but in the case where they are tabbed pages that are opened just one time when the applications starts. Would that be a problem and if so what would the problem be?







      xamarin xamarin.forms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 7:34









      Alan2

      1,44354132252




      1,44354132252






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You can, of course, subscribe here. But you will need to find a point in your page/app's lifecycle to unsubscribe. Else, this page might be alive forever, leaking memory.



          A better option might be to subscribe whenever it appears and unsubscribe when it disappears as suggested in the comments.



          You could also subscribe in the constructor and unsubscribe in the disappearing, but then the subscribe event will never happen again if the page is only instantiated once.






          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%2f53221504%2fcan-i-place-a-messagecenter-subscribe-in-tabbed-paged-that-are-only-ever-constru%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You can, of course, subscribe here. But you will need to find a point in your page/app's lifecycle to unsubscribe. Else, this page might be alive forever, leaking memory.



            A better option might be to subscribe whenever it appears and unsubscribe when it disappears as suggested in the comments.



            You could also subscribe in the constructor and unsubscribe in the disappearing, but then the subscribe event will never happen again if the page is only instantiated once.






            share|improve this answer

























              1














              You can, of course, subscribe here. But you will need to find a point in your page/app's lifecycle to unsubscribe. Else, this page might be alive forever, leaking memory.



              A better option might be to subscribe whenever it appears and unsubscribe when it disappears as suggested in the comments.



              You could also subscribe in the constructor and unsubscribe in the disappearing, but then the subscribe event will never happen again if the page is only instantiated once.






              share|improve this answer























                1












                1








                1






                You can, of course, subscribe here. But you will need to find a point in your page/app's lifecycle to unsubscribe. Else, this page might be alive forever, leaking memory.



                A better option might be to subscribe whenever it appears and unsubscribe when it disappears as suggested in the comments.



                You could also subscribe in the constructor and unsubscribe in the disappearing, but then the subscribe event will never happen again if the page is only instantiated once.






                share|improve this answer












                You can, of course, subscribe here. But you will need to find a point in your page/app's lifecycle to unsubscribe. Else, this page might be alive forever, leaking memory.



                A better option might be to subscribe whenever it appears and unsubscribe when it disappears as suggested in the comments.



                You could also subscribe in the constructor and unsubscribe in the disappearing, but then the subscribe event will never happen again if the page is only instantiated once.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 at 7:50









                Cherry Bu

                84628




                84628



























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53221504%2fcan-i-place-a-messagecenter-subscribe-in-tabbed-paged-that-are-only-ever-constru%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

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo