上面的函数可以正常运行,因为handler.postDelayed()方法需要传入一个Runnable对象作为参数,而DoneRunnable类实现了Runnable接口,所以可以作为参数传入。\n\n而下面的函数报错的原因是,handler.postDelayed()方法同样需要传入一个Runnable对象作为参数,但是android.os.Process.killProcess(android.os.Process.myPid())是一个void类型的方法,并不是Runnable对象,所以会报错。如果想要在延迟一段时间后执行killProcess()方法,需要创建一个Runnable对象,并在run()方法中调用killProcess()方法。


原文地址: https://www.cveoy.top/t/topic/pT2S 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录