Progressbar disappears in battery saver mode (Android 5.x)?

那年仲夏 提交于 2019-12-10 20:29:05

问题


I noticed that when the Battery saver mode is enabled (by the user or automatically) in Android 5.x - ProgressBars in application just disappear.

No animation, no static progressbar widget - just empty place.

How to prevent that? I understand when Battery saver disables some system animations, but progressbars is actually an important part of the application UI.

Just in case - code that implements ProgressBar Layout:

<ProgressBar
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/refresh_bar"
    android:layout_alignParentTop="true"
    android:indeterminate="true"
    android:visibility="gone"
    android:layout_marginTop="@dimen/progress_bar_top_margin" />

And how it's implemented in my fragment class:

public class FeedFragment extends Fragment {
    ...
    // Progressbar to show refreshing state
    private ProgressBar mRefreshBar;
    ...

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

            View v = inflater.inflate(R.layout.fragment_feed, container, false);    
            ...
            // Initialize and locate Refreshing progress bar
            mRefreshBar = (ProgressBar) v.findViewById(R.id.refresh_bar);
            ...
            mRefreshBar.setVisibility(View.VISIBLE);
            ...
     }
     ...
}

Also, I facing that problem with all progress bars in application, not only with this one. When Battery saver mode disabled - all works just fine.


回答1:


When Battery saver mode is enabled, every app on the device have the same issue.

Because Battery saver mode extends the battery life so that you can use the phone until you have a chance to charge it. It happens to every application. So don't worry.

How to prevent that?

By disabling Battery saver mode in Settings and then rebooting the device. Or you can request permission from the user to disable it.




回答2:


How to prevent that?

ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS allows you to request the user to allow your app to ignore battery optimizations, I haven't tried it out, but it seems legit.



来源:https://stackoverflow.com/questions/35221706/progressbar-disappears-in-battery-saver-mode-android-5-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!