[Android] Remove NavigationPage fragments after everything else is disposed (#1180)
* Add repro for 45702 * [Android] Remove fragments after everything else is disposed
This commit is contained in:
Родитель
15d8ac4142
Коммит
2b5f91c628
|
@ -0,0 +1,37 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
namespace Xamarin.Forms.Controls
|
||||
{
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Bugzilla, 45702, "Disabling back press on modal page causes app to crash", PlatformAffected.Android)]
|
||||
public class Bugzilla45702 : TestNavigationPage
|
||||
{
|
||||
protected override void Init()
|
||||
{
|
||||
Navigation.PushAsync(new NavigationPage(new MasterDetailPage() { Master = new ContentPage() { Title = "Master" }, Detail = new DetailPage() }));
|
||||
|
||||
MessagingCenter.Subscribe<DetailPage>(this, "switch", SwitchControl);
|
||||
}
|
||||
|
||||
void SwitchControl(object sender)
|
||||
{
|
||||
Application.Current.MainPage = new NavigationPage(new ContentPage { Content = new Label { Text = "Success" } });
|
||||
}
|
||||
|
||||
class DetailPage : ContentPage
|
||||
{
|
||||
public DetailPage()
|
||||
{
|
||||
var button = new Button { Text = "Click me" };
|
||||
button.Clicked += Button_Clicked;
|
||||
Content = button;
|
||||
}
|
||||
|
||||
void Button_Clicked(object sender, System.EventArgs e)
|
||||
{
|
||||
MessagingCenter.Send(this, "switch");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -336,6 +336,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla27731.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla59097.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla58875.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla45702.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla59718.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla59896.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla56771.cs" />
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace Xamarin.Forms.Controls
|
|||
SetMainPage(CreateDefaultMainPage());
|
||||
|
||||
//// Uncomment to verify that there is no gray screen displayed between the blue splash and red MasterDetailPage.
|
||||
//MainPage = new Bugzilla44596SplashPage(() =>
|
||||
//SetMainPage(new Bugzilla44596SplashPage(() =>
|
||||
//{
|
||||
// var newTabbedPage = new TabbedPage();
|
||||
// newTabbedPage.Children.Add(new ContentPage { BackgroundColor = Color.Red, Content = new Label { Text = "yay" } });
|
||||
|
@ -43,7 +43,10 @@ namespace Xamarin.Forms.Controls
|
|||
// Master = new ContentPage { Title = "Master", BackgroundColor = Color.Red },
|
||||
// Detail = newTabbedPage
|
||||
// };
|
||||
//});
|
||||
//}));
|
||||
|
||||
//// Uncomment to verify that there is no crash when switching MainPage from MDP inside NavPage
|
||||
//SetMainPage(new Bugzilla45702());
|
||||
}
|
||||
|
||||
public Page CreateDefaultMainPage()
|
||||
|
|
|
@ -128,20 +128,6 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
|
|||
{
|
||||
_disposed = true;
|
||||
|
||||
// API only exists on newer android YAY
|
||||
if ((int)Build.VERSION.SdkInt >= 17)
|
||||
{
|
||||
FragmentManager fm = FragmentManager;
|
||||
|
||||
if (!fm.IsDestroyed)
|
||||
{
|
||||
FragmentTransaction trans = fm.BeginTransaction();
|
||||
foreach (Fragment fragment in _fragmentStack)
|
||||
trans.Remove(fragment);
|
||||
trans.CommitAllowingStateLoss();
|
||||
fm.ExecutePendingTransactions();
|
||||
}
|
||||
}
|
||||
|
||||
if (_toolbarTracker != null)
|
||||
{
|
||||
|
@ -206,6 +192,21 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
|
|||
}
|
||||
|
||||
Device.Info.PropertyChanged -= DeviceInfoPropertyChanged;
|
||||
|
||||
// API only exists on newer android YAY
|
||||
if ((int)Build.VERSION.SdkInt >= 17)
|
||||
{
|
||||
FragmentManager fm = FragmentManager;
|
||||
|
||||
if (!fm.IsDestroyed)
|
||||
{
|
||||
FragmentTransaction trans = fm.BeginTransaction();
|
||||
foreach (Fragment fragment in _fragmentStack)
|
||||
trans.Remove(fragment);
|
||||
trans.CommitAllowingStateLoss();
|
||||
fm.ExecutePendingTransactions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
|
|
Загрузка…
Ссылка в новой задаче