Prevent FormsAppCompatActivity from loading fragments we don't use on restart (#246)
* Prevent FormsAppCompatActivity from loading fragments we don't use on restart * Adding issues lost in merge
This commit is contained in:
Родитель
d52f110d78
Коммит
be9f626c37
|
@ -0,0 +1,39 @@
|
||||||
|
using Xamarin.Forms.CustomAttributes;
|
||||||
|
using Xamarin.Forms.Internals;
|
||||||
|
|
||||||
|
namespace Xamarin.Forms.Controls
|
||||||
|
{
|
||||||
|
[Preserve (AllMembers = true)]
|
||||||
|
[Issue (IssueTracker.Bugzilla, 42075, "IllegalStateException - Fragment does not have a view", PlatformAffected.Android)]
|
||||||
|
public class Bugzilla42075 : TestTabbedPage
|
||||||
|
{
|
||||||
|
protected override void Init()
|
||||||
|
{
|
||||||
|
Title = "Outer";
|
||||||
|
|
||||||
|
const string text = @"To run this test, you'll need to have an emulator or device in Developer mode, with the ""Don't Keep Activities"" setting turned on.
|
||||||
|
Hit the Home button to dismiss the application. Then bring up the Overview (recent apps) screen and select the Control Gallery.
|
||||||
|
If the application crashes with ""Java.Lang.IllegalStateException: Fragment does not have a view"", this test has failed. If the application does not crash or crashes with a different exception, this test has passed.";
|
||||||
|
|
||||||
|
var directions = new ContentPage
|
||||||
|
{
|
||||||
|
Content = new StackLayout()
|
||||||
|
{
|
||||||
|
Children =
|
||||||
|
{
|
||||||
|
new Label()
|
||||||
|
{
|
||||||
|
Text = text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var tabbedPage = new TabbedPage() {Title = "Inner"};
|
||||||
|
tabbedPage.Children.Add(new ContentPage());
|
||||||
|
|
||||||
|
Children.Add(directions);
|
||||||
|
Children.Add(tabbedPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -110,6 +110,7 @@
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41205.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41205.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41424.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41424.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42074.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42074.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42075.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" />
|
||||||
|
|
|
@ -44,6 +44,9 @@ namespace Xamarin.Forms.Platform.Android
|
||||||
int _statusBarHeight = -1;
|
int _statusBarHeight = -1;
|
||||||
global::Android.Views.View _statusBarUnderlay;
|
global::Android.Views.View _statusBarUnderlay;
|
||||||
|
|
||||||
|
// Override this if you want to handle the default Android behavior of restoring fragments on an application restart
|
||||||
|
protected virtual bool AllowFragmentRestore => false;
|
||||||
|
|
||||||
protected FormsAppCompatActivity()
|
protected FormsAppCompatActivity()
|
||||||
{
|
{
|
||||||
_previousState = AndroidApplicationLifecycleState.Uninitialized;
|
_previousState = AndroidApplicationLifecycleState.Uninitialized;
|
||||||
|
@ -139,8 +142,17 @@ namespace Xamarin.Forms.Platform.Android
|
||||||
callback(resultCode, data);
|
callback(resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override void OnCreate(Bundle savedInstanceState)
|
protected override void OnCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
|
if (!AllowFragmentRestore)
|
||||||
|
{
|
||||||
|
// Remove the automatically persisted fragment structure; we don't need them
|
||||||
|
// because we're rebuilding everything from scratch. This saves a bit of memory
|
||||||
|
// and prevents loading errors from child fragment managers
|
||||||
|
savedInstanceState?.Remove("android:support:fragments");
|
||||||
|
}
|
||||||
|
|
||||||
base.OnCreate(savedInstanceState);
|
base.OnCreate(savedInstanceState);
|
||||||
|
|
||||||
AToolbar bar;
|
AToolbar bar;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче