我的代码中有一个变量,说它是"状态".
我想根据此变量值在应用程序中显示一些文本.这必须在特定的时间延迟下完成.
就像是,
检查状态变量值
显示一些文字
等待10秒钟
检查状态变量值
显示一些文字
等待15秒
等等.时间延迟可能会有所不同,一旦显示文本就会设置.
我试过Thread.sleep(time delay)但失败了.有没有更好的方法来完成这项工作?
我正在尝试更新音乐播放器SeekBar,但没有任何反应.服务在我的活动中启动正常并正确绑定(因为我可以使用我服务中的一些方法和音乐播放正常).这是我的服务代码:
public class MusicPlayerService extends Service {
MediaPlayer myMusicPlayer;
String path;
Intent getMusicId = new Intent();
// Binder given to clients
private final IBinder mBinder = new LocalBinder();
/**
* Class used for the client Binder. Because we know this service always
* runs in the same process as its clients, we don't need to deal with IPC.
*/
public class LocalBinder extends Binder {
MusicPlayerService getService() {
// Return this instance of LocalService so clients can call public methods …Run Code Online (Sandbox Code Playgroud)