Skip to content

Commit

Permalink
Merge pull request #1945 from AmrAlSayed0/patch-1
Browse files Browse the repository at this point in the history
Fixes NRE when app put to sleep when MainPage isn't set
  • Loading branch information
brianlagunas committed Nov 7, 2019
2 parents 0597260 + c9a11d9 commit 543f539
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Source/Xamarin/Prism.Forms/PrismApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,20 @@ protected virtual void InitializeModules()

protected override void OnResume()
{
var page = PageUtilities.GetCurrentPage(MainPage);
PageUtilities.InvokeViewAndViewModelAction<IApplicationLifecycleAware>(page, x => x.OnResume());
if (MainPage != null)
{
var page = PageUtilities.GetCurrentPage(MainPage);
PageUtilities.InvokeViewAndViewModelAction<IApplicationLifecycleAware>(page, x => x.OnResume());
}
}

protected override void OnSleep()
{
var page = PageUtilities.GetCurrentPage(MainPage);
PageUtilities.InvokeViewAndViewModelAction<IApplicationLifecycleAware>(page, x => x.OnSleep());
if (MainPage != null)
{
var page = PageUtilities.GetCurrentPage(MainPage);
PageUtilities.InvokeViewAndViewModelAction<IApplicationLifecycleAware>(page, x => x.OnSleep());
}
}

private void PrismApplicationBase_ModalPopping(object sender, ModalPoppingEventArgs e)
Expand Down

0 comments on commit 543f539

Please sign in to comment.