package com.example.timer1;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.widget.TextView;
public class ServiceClass extends Service {
private int minute = 0;
private int second = 0;
private int t100ms = 0;
private TextView text;
private Handler handler = new Handler();
@Override
public IBinder onBind(Intent intent) {
return null;
}
public void onStart(Intent intent, int startId) {
Log.d("slog", "onStart()");
super.onStart(intent, startId);
handler.removeCallbacks(doUpdateTimer);
handler.postDelayed(doUpdateTimer, 1);
// final Button buttonStart =(Button) findViewById(R.id.ButtonStop);
}
@Override
public void onDestroy() {
Log.d("slog", "onDestroy()");
handler.removeCallbacks(doUpdateTimer);
super.onDestroy();
}
private Runnable doUpdateTimer = new Runnable() {
public void run() {
t100ms++;
if (t100ms >= 10) {
t100ms = 0;
second++;
if (second >= 60) {
second = 0;
minute++;
if (minute >= 60)
minute = 0;
}
}
text = (TextView) findViewById(R.id.TextView01);
String strFormat = String.format("%02d:%02d:%2d", minute, second,
t100ms);
text.setText(strFormat);
handler.postDelayed(doUpdateTimer, 100);
}
};
}
우선, 제가 생각한거는...
첫번째 액티비티에서 서비스에있는 타이머를 계속 실행시키면서 액티비티마다 시간흘러가는것을 보여주고, 마지막액티비티에서 중지되었을때
타이머도 멈추게 하려고합니다.
초보이기때문에 여기저기서 본거 긁어온건데 문제가 되는게 뭔지...모르겠습니다
거의 마지막쯤에있는 text = (TextView) findViewById(R.id.TextView01);
여기가 에러가나옵니다. findViewById 에서... 이유를 당췌모르겠습니다..ㅠㅠㅠㅠ...
어떻게해야 이것을해결하고 제가원하는 방향으로 구현할수있을까요?..