"Java.Lang.IllegalStateException: Activity has been destroyed" when using AdMob

ChristerOlssonChristerOlsson Christer OlssonUSMember

I have done some tests of how to use AdMob in Xamarin.Forms and I got stuck on this.

  • A MasterDetailPage containing an empty master and a detail that is a new NavigationPage(myAdPage)
  • Start the application
  • Click on the (test)-ad and it will open a window
  • Click on the hardware back button twice and you get Java.Lang.IllegalStateException: Activity has been destroyed

A simple solution is attached.

Any clues of what to change to avoid this crash?

Best Answers


  • ChristerOlssonChristerOlsson Christer Olsson USMember

    Digged further into this. It does not seem to have anything to do with AdMob. I replace AdMob with a button that pushed another page to the navigation stack. This gives the same result.
    Java.Lang.IllegalStateException: Activity has been destroyed

  • DoganCoruhDoganCoruh Dogan Çoruh USMember

    I am getting the same exception but i am not using admob. There is no clue about this exception clearly. Another guy says that this is a lifecycle issue OnCreate fixes instead of OnResume but not worked for me :(

  • ChristerOlssonChristerOlsson Christer Olsson USMember

    This is a problem in of Xamarin.Forms. works great.

  • JohnHardmanJohnHardman John Hardman GBUniversity ✭✭✭✭✭

    @ChristerOlsson @DoganCoruh - this sounds like https://bugzilla.xamarin.com/show_bug.cgi?id=46494 for which @AdrianKnight has provided a fix that the bug report suggests is included in 2.3.4-pre1

  • ChristerOlssonChristerOlsson Christer Olsson USMember

    Yes, it does. Thanks!

  • BinuraDodangodaBinuraDodangoda Binura Dodangoda USMember
    edited December 2016

    @ChristerOlsson said:
    This is a problem in of Xamarin.Forms. works great.

    I had a problem in closing the app. That means when I press the back button to close the app, the app gets crashed. After I downgrading Xamarin.Forms to the version, the problem was solved !

  • LuccasClezarLuccasClezar Luccas Clezar USMember
    edited January 7

    I'm having the same problem of @BinuraDodangoda. When I close with the back button, Android displays a message saying that the application stopped working. From what I know this is a problem related to having a NavigationPage as the Detail of a MasterDetailPage. I think that the NavigationPage tries to handle the navigation but the system is closing the app, resulting in Android saying that the activity has been destroyed.

  • KhalilSarkawiKhalilSarkawi Khalil Sarkawi USMember

    I'm having the same problem too when i reopen the application (like when press on notification).
    i have mater detail page and navigation page as detail .
    i try to install xamarin.forms v2.3.3.180 (released on 5-1-2017) but not worked too.

  • StevePearson.7302StevePearson.7302 Steve Pearson GBMember

    Tried 2.3.4-pre1 but the problem looks like its still there.

  • jurmb84jurmb84 Richard Bolek USMember

    Apparently there is a fix in the works and part of 2.3.4


    So the question I would like answered is, Could this get added to the 2.3.3 line and released... or could someone point me to good documentation on how to custom build xamarin from github so I can put it in a working build myself?

    Thanx in advance...

  • CrosevenCroseven Donald Jansen USMember

    xamarin.forms v2.3.3.180 have the same problem. when will 2.3.4 come

  • DoganCoruhDoganCoruh Dogan Çoruh USMember

    For God sake, please fix that problem guys...

  • Lewis_tLewis_t Lewis Todd GBUniversity

    I don't see how you can have a stable version out there with this kind of bug in it. It should be a critical fix for 2.3.3 in my opinion. We had to hold back to 2.3.2 for our last version for this and a couple of other issues. hopefully 2.3.4 will be stable enough by the time we're ready to release again.

  • ChristerOlssonChristerOlsson Christer Olsson USMember
    edited February 22

    Tried with but still not working. Followed codercampos advice above (clean, delete obj/bin, rebuild) and it worked.

  • JoeMankeJoeManke Joe Manke USMember ✭✭✭
    edited March 14

    For anyone looking for a really cheap hack until 2.3.4 is stable, this will keep your users from getting an error message after backing out of the app:

    protected override void OnDestroy()
        App.Current.MainPage = new ContentPage();
Sign In or Register to comment.