locked
TabbedPage - OnAppearing called twice in android RRS feed

  • Question

  • User363938 posted

    Hello,

    We have a TabbedPage layout and our app makes the web service call in the OnAppearing of the tab page. The OnAppearing event is called properly in iOS but in Android we are observing that the OnAppearing gets called twice. Due to this behaviour we are having problem making proper endpoint call in the onAppearing for android.

    I can see that this is an issue reported in BugZilla but I dont see any proper resolution on the issue. https://bugzilla.xamarin.com/show_bug.cgi?id=44211

    This is really annoying as one way or other we are dependent on the onAppearing method. We tried to add some local variables to make sure the function gets called only once like so.

    constructor()
    {
    .....
     called = false;
    }
    
    protected override void OnAppearing()
    {
        if(!called){
            ....
            called = true;
        }
    }
    

    With this method onAppearing does not get triggered after the first time. ( Not getting called on further change of tabs )

    Is there any better way to do this? Also any update on the issue would also be helpful.

    Monday, April 16, 2018 2:13 PM

Answers

  • User180523 posted

    Afterthoughts... So the logic is so fragile that calling the page twice breaks the app? If someone doube-taps the button to go to that page... If someone switches away from your app then back while that page is open... hits the back button then back to that page... any normal navigation would cause a cause hit of the OnAppearing and thus crashes your app? Sounds like you need to work out the actual problem and not just band-aid the symptom.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, April 16, 2018 2:40 PM

All replies

  • User180523 posted

    Bugzilla hasn't been the reporting/tracking system for months. Maybe close to a year. Updates are probably not being made there.

    You should locate the corresponding bug report on the Xamarin.Forms nuget issues page. That should give you an up-to-date status. https://github.com/xamarin/Xamarin.Forms/issues

    Monday, April 16, 2018 2:36 PM
  • User180523 posted

    Afterthoughts... So the logic is so fragile that calling the page twice breaks the app? If someone doube-taps the button to go to that page... If someone switches away from your app then back while that page is open... hits the back button then back to that page... any normal navigation would cause a cause hit of the OnAppearing and thus crashes your app? Sounds like you need to work out the actual problem and not just band-aid the symptom.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, April 16, 2018 2:40 PM
  • User363938 posted

    @ClintStLaurent : Thanks for the comment. After further review on the app lifecycle we found that, Android tries to cache the pages in TabbedPage and executes the onAppearing of the nearby pages as well (ViewPager behaviour). We had some conditional code in the OnAppearing which did not execute and so when we switch to that tab, onAppearing did not get triggered again and we had a crash.

    So like you suggested we refactored the code so that we are not longer fully dependent on the onAppearing getting called everytime.

    Wednesday, April 18, 2018 11:22 AM
  • User180523 posted

    @sriram15 said: we found that, Android tries to cache the pages in TabbedPage and executes the onAppearing of the nearby pages as well

    Huh. Wow. Great find. I've never done a TabbedPage app so I personally never ran across this. Makes me curious if it is android doing that and Xamarin is just at its mercy... Or if its Xamarin.

    Wednesday, April 18, 2018 12:11 PM