Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animators may only be run on Looper threads on Sherlock Action Bar

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.

like image 645
JR Tan Avatar asked Apr 02 '14 06:04

JR Tan


2 Answers

Solved it by using

new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                                getSupportActionBar().hide();
                        }
                    }, 1000);
like image 98
JR Tan Avatar answered Nov 06 '22 07:11

JR Tan


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

Use this because the parameterless constructer handler is deprecated.

like image 39
Om kumar Yadav Avatar answered Nov 06 '22 07:11

Om kumar Yadav