edsnider / localnotificationsplugin

Local Notifications Plugin for Xamarin and Windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clicking the notification resets ViewModel variables

ouijahija opened this issue · comments

Bug

Plugin Version: 3.0.1
Platform: Xamarin.Forms 3.1.0.697729
Device/Hardware: Moto Z(2) Force

Expected behavior

The App resumes when clicking the notification.

Actual behavior

The App opens and seems to be reseted (Variables of ViewModels are set back to default). Some variables from other plugins (e.g. Plugins.BluetoothLE from aritchie) are not reseted.
I suspect, that the error #10 stems from the same bug (Because the inconsistent variables lead to a faulty application logic)

Steps to reproduce the behavior

  • Create a Xamarin.Forms.Android Project with Masterdetail
  • Create a ContentPage with the following methods:
protected override void OnAppearing()
{
          base.OnAppearing();
          MessagingCenter.Unsubscribe<App>(this, App.ON_SLEEP_KEY_VALUE);
          CrossLocalNotifications.Current.Cancel(101);
}

protected override void OnDisappearing()
{
          base.OnDisappearing();

          MessagingCenter.Subscribe<App>(this, App.ON_SLEEP_KEY_VALUE, app =>
          {
                    //viewModel.DisposeScan();
                    CrossLocalNotifications.Current.Show("App", "App is currently running in Background.", 101);     
           });
}

and add this to your App class

public const string ON_SLEEP_KEY_VALUE = "SpecialOnSleepKeyValue";

protected override void OnSleep ()
{
       MessagingCenter.Send(this, ON_SLEEP_KEY_VALUE);
}