xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.53k stars 506 forks source link

[Android] [Battery] Remove code duplication #2111

Closed Samidarex closed 7 months ago

Samidarex commented 7 months ago

Description of Change

Extracted duplicate code, into a new method. Tests and samples were ommited as the changes doesn't alternate the current class behavior.

Duplicate code:

try
{
    Platform.AppContext.UnregisterReceiver(receiver);
}
catch (Java.Lang.IllegalArgumentException)
{
    System.Diagnostics.Debug.WriteLine("{Receiver name} receiver already unregistered. Disposing of it.");
}

Bugs Fixed

API Changes

None

Behavioral Changes

None

PR Checklist

jfversluis commented 7 months ago

Hey @Samidarex thanks so much for your work on this!

Looking at the Xamarin.Essentials lifespan that remains we want to only change the bare minimum so that we don't risk any regressions. Since this only addresses a thing to make the code a bit cleaner and not much else I'm going to close this one for now. You might want to check if this is still the same in .NET MAUI and maybe make your change also there!

Again thanks, much appreciated. If you're looking for any work to do here please reach out and we can surely find you something 😉