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 : https://theconfuzedsourcecode.wordpress.com/2015/06/19/so-i-just-implemented-push-notifications-in-awesome-xamarin-forms/

Best Answer

Answers

  • 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 ✭✭

    Hello,
    have you solved this problem ?
    I have the same issue

    Thanks

  • MatteoPiccioniMatteoPiccioni USMember ✭✭

    Thanks

  • 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()
    {
    try
    {
    base.OnDestroy();
    }
    catch (Exception ex)
    {
    ex.ToString();
    }
    }

    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 (4.4.0.34) and Xamarin Forms 2.3.4.224, 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;
    _currentActivity.MoveTaskToBack(true);
    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.