I wanted to hide the action bar after the 1 second delay,

Timer().schedule(new TimerTask() {
                        @Override
                        public void run() {
                                getSupportActionBar().hide();
                        }
                    }, 1000);

Getting crash after I ran the code..

android.util.AndroidRuntimeException: Animators may only be run on Looper threads

Is there any solution for this issue? Thanks.

有帮助吗?

解决方案

Solved it by using

new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                                getSupportActionBar().hide();
                        }
                    }, 1000);

其他提示

new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
    // Your Code
}
}, 1000);

Use this because the parameterless constructer handler is deprecated.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top