且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是相当于一个JavaScript的setInterval / setTimeout的在Android的/ Java的?

更新时间:2023-10-30 09:09:52

像往常一样与Android有办法做到这一点的负载,但假设你只是想在同一个线程点点后运行一段codeA ,我用这样的:

As always with Android there's loads of ways to do this, but assuming you simply want to run a piece of code a little bit later on the same thread, I use this:

new android.os.Handler().postDelayed(
    new Runnable() {
        public void run() {
            Log.i("tag", "This'll run 300 milliseconds later");
        }
    }, 
300);

..这是pretty的多少等同于

.. this is pretty much equivalent to

setTimeout( 
    function() {
        console.log("This'll run 300 milliseconds later");
    },
300);