Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 2c6b06a

Browse files
Kevin PetitKevin Petit
Kevin Petit
authored and
Kevin Petit
committed
More fixes.
1 parent a123fc9 commit 2c6b06a

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ protected override void OnPause()
229229
{
230230
_layout.HideKeyboard(true);
231231

232+
if (Forms.IsLollipopOrNewer)
233+
{
234+
// Don't listen for power save mode changes while we're paused
235+
UnregisterReceiver(_powerSaveModeBroadcastReceiver);
236+
}
237+
232238
// Stop animations or other ongoing actions that could consume CPU
233239
// Commit unsaved changes, build only if users expect such changes to be permanently saved when thy leave such as a draft email
234240
// Release system resources, such as broadcast receivers, handles to sensors (like GPS), or any resources that may affect battery life when your activity is paused.
@@ -238,12 +244,6 @@ protected override void OnPause()
238244
_previousState = _currentState;
239245
_currentState = AndroidApplicationLifecycleState.OnPause;
240246

241-
if (Forms.IsLollipopOrNewer)
242-
{
243-
// Don't listen for power save mode changes while we're paused
244-
UnregisterReceiver(_powerSaveModeBroadcastReceiver);
245-
}
246-
247247
OnStateChanged();
248248
}
249249

@@ -320,7 +320,7 @@ void AppOnPropertyChanged(object sender, PropertyChangedEventArgs args)
320320
}
321321

322322
if (args.PropertyName == nameof(_application.MainPage))
323-
InternalSetPage(_application.MainPage);
323+
SetMainPage();
324324
if (args.PropertyName == PlatformConfiguration.AndroidSpecific.Application.WindowSoftInputModeAdjustProperty.PropertyName)
325325
SetSoftInputMode();
326326
}

Xamarin.Forms.Platform.Android/AppCompat/Platform.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,17 @@ void SetPageInternal(Page newRoot)
322322

323323
void Cleanup(List<AView> viewsToRemove, List<IVisualElementRenderer> renderersToDispose)
324324
{
325-
new Handler(Looper.MainLooper).Post(() =>
325+
// If trigger by dispose, cleanup now, otherwise queue it for later
326+
if (_disposed)
327+
{
328+
DoCleanup();
329+
}
330+
else
331+
{
332+
new Handler(Looper.MainLooper).Post(DoCleanup);
333+
}
334+
335+
void DoCleanup()
326336
{
327337
for (int i = 0; i < viewsToRemove.Count; i++)
328338
{
@@ -333,9 +343,10 @@ void Cleanup(List<AView> viewsToRemove, List<IVisualElementRenderer> renderersTo
333343
for (int i = 0; i < renderersToDispose.Count; i++)
334344
{
335345
IVisualElementRenderer rootRenderer = renderersToDispose[i];
346+
rootRenderer?.Element.ClearValue(Android.Platform.RendererProperty);
336347
rootRenderer?.Dispose();
337348
}
338-
});
349+
}
339350
}
340351

341352
void AddChild(Page page, bool layout = false)

0 commit comments

Comments
 (0)