Xamarin.forms: Animation tasks do not complete when Battery Saver enabled

Created on 11 Jan 2018  ·  20Comments  ·  Source: xamarin/Xamarin.Forms

Migrated from https://bugzilla.xamarin.com/show_bug.cgi?id=56831

Steps to reproduce

  1. Enable Battery Saver mode on an Android phone that disables animation whilst the mode is enabled (such as Nexus 6P on Android 7.1.2)
  2. Call any animation - var animationTask = label.FadeTo(1)
  3. await the resulting task

Expected behavior

Animation completes instantly, Task immediately completes.

Actual behavior

Animation does not occur, Task never completes. Tested with Xamarin.Forms 2.3.4.247.

This caused our production app to completely break on several phones when Battery Saver was enabled, due to a start-up animation never completing.

This bug can also be emulated by setting "Animator duration scale" to “Animation off” in Android developer options.

Work-around

We're using code like this to prevent calling animation methods:

bool AreAnimationsDisabled()
{
    var powerManager = Application.Context.GetSystemService(Context.PowerService) as PowerManager;
    if (powerManager != null)
    {
        if(powerManager.IsPowerSaveMode)
        {
            return true;
        }
    }

    return Settings.Global.GetFloat(Application.Context.ContentResolver, Settings.Global.AnimatorDurationScale, 0) == 0;
}

Basic Information

  • Version with issue: 2.3.4.247
  • Platform Target Frameworks:

    • Android: 7.1.2

Reproduction Link

AnimationDisabledTask (1).zip

5 high impact Android bug

Most helpful comment

Note the sample code to check if animations are disabled had a subtle bug, it should be:

Settings.Global.GetFloat(Application.Context.ContentResolver, Settings.Global.AnimatorDurationScale, 1) == 0;

The third parameter has changed to 1 - if the setting hadn't been defined, it should be assumed animations are enabled.

All 20 comments

Note the sample code to check if animations are disabled had a subtle bug, it should be:

Settings.Global.GetFloat(Application.Context.ContentResolver, Settings.Global.AnimatorDurationScale, 1) == 0;

The third parameter has changed to 1 - if the setting hadn't been defined, it should be assumed animations are enabled.

Is there any news on this?

I'm also affected in my Xamarin Forms application using XF 2.3.4.247. Is there any work in progress regarding this issue?

This issue also appear in Xamarin.Forms 2.5.0.280555

Does Microsoft have any plans/timeline to fix it? The issue blocks all commercial applications in our case. I don't believe this is king of issue that can leave untouched for a year like it is now. It breaks our trust to Xamarin. @jamesmontemagno I would like to ask You for a comment on how we can make this issue more visible so that it is put into the timeline. I will appreciate your response :) I',m just looking for a help everywhere I can.

I agree with Pawel! We made workarounds in our code, but we still have problems, because we're using lib which also calling animation methods and freeze all our UI. And what we should do? Fork library, fix Xamarin bug and support custom library version? It doesn't look good for me. Please, fix it as soon as possible.

Fork is not an option for long life cycle apps. I also have an impression that no one cares about such a serious bug. Please help and fix this.

Agreed @PawelGasiorowski, absolute joke how long these things take to be addressed and also how many things break with each and every release.

Any update?

Still waiting.... @jamesmontemagno we would be very happy if XF team would join the topic.

I've just had two users report issues with my App that are still affected by this problem. I don't understand why this is not being fixed or why the XF team does not respond?

Hi all, this is scheduled for work on the 3.1 milestone, so hopefully we will get to it.

In the meantime, @tomgilder proposed a way to check this independently.

We use android's ValueAnimator as a base for out Ticker. When ValueAnimator.AreAnimatorsEnabled is false, the ticker no longer ticks.

There are (at least) 2 ways of fixing this:

  1. use a System.Threading.Timer as ticker on Android (like it's done in Tizen platform)
  2. add a virtual property to Ticker IsTickerEnabled, and check its value before doing a Ticker.Default.Insert(), and either fake the Ticker (bad, unless se use a slow ticking one), or finish the animation right away.

/cc @jassmith

If in lower battery mode animations should ideally be turned off. I thought that android's system itself handles this when using the framework APIs. I would turn them off IMHO.

Thank you for the answer @jamesmontemagno

Let me describe my issue a bit more...

In my case we are using Xamarin Forms animations like fading. This changes Opacity value of an element. Power save mode implementation is (as far as I noticed) manufacturer specific. We noticed this issue on google pixel 2 - the animation task does not work/start at all so the UI parts I would like to display with the fade effect does not display. The power save mode is enabled by default in Pixel. I also don't know how to turn it off.

In the application I have a few nite menus that slide down or fade in. Everythig is based on AbsoluteLayout coitainer so it is almost not possible to give up the effects. What else I have noticed is that all other Tasks works so it is only related to XF animations.

I know this is fixed now, but wanted to let everyone know we did add a way to detect for lower power mode via Xamarin.Essentials: https://docs.microsoft.com/en-us/xamarin/essentials/power

I didn't know there's an issue nor a fix to this problem, as I described here #5392, I think it should be reopened

This issue still appears when animations are disabled, via accessibility options on the device

@trolloks Please open a new issue.

@trolloks Please open a new issue.

Started #5686

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MartinWegner picture MartinWegner  ·  3Comments

simontocknell picture simontocknell  ·  3Comments

EmilAlipiev picture EmilAlipiev  ·  3Comments

mfeingol picture mfeingol  ·  3Comments

deakjahn picture deakjahn  ·  3Comments