使用AtomicBoolean监视android中正在运行的线程或方法

时间:2023-01-26 09:01:44

I have an AtomicBoolean in my service class for an android app. I wanted to monitor the variable have it shut down a media player if the value is false and keep it running if the value is true. which of the lifecycle methods should i put this testing while loop in?

我的服务类中有一个用于Android应用程序的AtomicBoolean。我希望监视变量,如果值为false,则关闭媒体播放器,如果值为true,则保持运行。我应该在循环中进行哪些生命周期方法?

1 个解决方案

#1


0  

If you want to monitor, then you would want to set up a recurring timer in the onStartCommand() method of the Service class. Keep in mind that this puts the responsibility on you to stop the Service when your work is finished.

如果要监视,则需要在Service类的onStartCommand()方法中设置定期计时器。请记住,当您的工作完成时,这将使您有责任停止服务。

#1


0  

If you want to monitor, then you would want to set up a recurring timer in the onStartCommand() method of the Service class. Keep in mind that this puts the responsibility on you to stop the Service when your work is finished.

如果要监视,则需要在Service类的onStartCommand()方法中设置定期计时器。请记住,当您的工作完成时,这将使您有责任停止服务。