android studio-如何停止runnable?

jaql4c8m  于 2021-07-04  发布在  Java
关注(0)|答案(0)|浏览(253)

请教我如何停止跑步。”handler.removecallback(ss)“不起作用。还是我的程序错了?

int life = 100, damage = 5;
public void gameOver()
{
    ((TextView)findViewById(R.id.textView6)).setVisibility(View.VISIBLE);
}
final Runnable sS = new Runnable()
    {
        @Override
        public void run()
        {
            life = life - damage;
            String lifeHP = String.valueOf(life);
            ((TextView)findViewById(R.id.textView)).setText(lifeHP);
            handler.postDelayed(this, 300);
            if (life < 0 )
            {
                gameOver();
                //handler.removeCallback(ss)--does not work.
            }
        }
    };
    handler.post(sS);

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题