Forum Xamarin.Forms

Getting error Activity has been destroyed

mostafamarjimostafamarji USMember
edited January 2017 in Xamarin.Forms

My application is based on masterdetailedpage and I am working with push notification. When user click on the notification I want to navigate to a specific page. All the process is working fine but at the end of the proccess I got this error Java.Lang.IllegalStateException: Activity has been destroyed .

My code for push notification is based on this link :

Best Answer


  • ClapotiClapoti CAMember ✭✭

    I have the same kind of problem.
    When using a Master Detail and pressing back, it "closes" my app and I get the Java.Lang error.
    But if I use a NavigationPage I don't have that exception.
    Anybody knows how to fix this ?

  • MatteoPiccioniMatteoPiccioni USMember ✭✭

    have you solved this problem ?
    I have the same issue


  • MatteoPiccioniMatteoPiccioni USMember ✭✭


  • ccamiloccamilo FIMember

    @Clapoti said:
    Well I didn't fix it because apparently it is a Xamarin bug, but in my MainActivity.cs file in the Droid project I added this to "silence" the exception.

    //TODO Remove this when fixed by Xamarin
    protected override void OnDestroy()
    catch (Exception ex)

    Thank you!! I wasted a lot of time finding an explanation but your solution solves it all. Cheers!

  • ClapotiClapoti CAMember ✭✭

    By the way, when using the latest version of Xamarin ( and Xamarin Forms, the bug is fixed.

  • MosCDMosCD Member ✭✭
    edited January 2018

    Some help here please
    I am having the exact same problem. and the solution presented here is not suitable to solve my problem
    Since in my case the "back" process for my App is not part of the navigation logic for my app
    When the user clicks a link in the "Detail" page, the App loads another page navigating away from the MasterDetailPage
    -User click on "Accounts" link inside detail page which calls a function in App

    MainPage = new NavigationPage(new AccountsPage());

    and here the bug comes

    now if I used the solution of dependency service and called
    var _currentActivity = Forms.Context as Activity;
    it simply exits the App

    I want a behavior to take me to the Xamarin.Forms AccountsPage

    Could any one help

  • MosCDMosCD Member ✭✭

    Sorry the post was supposed to be on other thread

Sign In or Register to comment.