我正在开发一个滑雪追踪器应用程序,但我在第一个任务中失败了 :) 秒表
这是我的服务:
public class TrackerService extends Service {
private IBinder mBinder = new TrackerBinder();
private TimerThread thread;
private int min =0,sec=0;
private boolean running = true;
@Override
public void onCreate() {
thread = new TimerThread();
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
public void startTimer(){
if(!thread.isAlive())
thread.start();
else{
thread.resume();
}
}
public void pauseTimer(){
thread.suspend();
}
public class TrackerBinder extends Binder{
public TrackerService getService(){
return TrackerService.this;
}
}
public class TimerThread extends Thread{
@Override
public void run() {
while (running){
sec++;
if(sec==60){
min++;
sec=0;
}
try {
Thread.sleep(1000);
}catch(Exception e){}
}
}
}
}
我正在从绑定的活动中调用 startTimer() 和 pauseTimer() 方法,但在恢复时我得到了 java.lang.UnsopportedOperationException。知道如何解决吗?