protected override void OnDestroy()
 {
     if (AppState.UserIsLoggedIn)
     {
         AppSettings.UserWasLoggedInLastAppClose = true;
     }
     else
     {
         AppSettings.UserWasLoggedInLastAppClose = false;
     }
     try
     {
         //UnregisterReceiver(ForegroundReceiver); //@TODO check what this does
         //
         AppState.NotificationStartedApp = false;
         MainPlaybackSticky.NotificationShouldPlayInBkgrd = false; // set this to false if user closes the app so that future notification clicks will restart the app
     }
     catch { }
     ViewPager.PageSelected -= ViewPager_PageSelected;
     NavigationView.NavigationItemSelected -= NavigationView_NavigationItemSelected;
     try { MainPlaybackSticky.ExternalStopForeground();
           AppState.ForeNote = null; }
     catch (Exception ex) { }
     try
     {
         foreach (var wv in PlaystateManagement.WebViewIdDictionary)
         {
             wv.Value.LoadUrl(JavascriptCommands._jsPauseVideo);
         }
     }
     catch { }
     MainPlaybackSticky.AppIsMovingIntoBackgroundAndStreaming = false;
     base.OnDestroy();
 }