CountDownTimer を使用しているサービスがあります。
問題は - のonTick(...)
関数内で、CountDownTimer class
使用する必要があることです
ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
問題は、次のエラーが発生することです 。 メソッド getSystemService(String) は、型 FBBlockerService.FBServicelockCountdownTimer に対して未定義です。
この問題を回避する方法はありますか?
public class FBBlockerService extends Service {
int totalSeconds_Service;
boolean isRunning_Service;
Timer timer;
private CountDownTimer timerService;
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
timerService = new FBServicelockCountdownTimer(totalSeconds_Service * 1000, 1000);
timerService.start();
return START_NOT_STICKY; // need this START_REDELIVER_INTENT?
}
public class FBServicelockCountdownTimer extends CountDownTimer {
public FBServicelockCountdownTimer(long millisInFuture,
long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}
@Override
public void onFinish() {
Log.v("fbblocker Service", "in onFinish FBServicelockCountdownTimer inside SERVICE");
stopForeground(true);
}
@Override
public void onTick(long millisUntilFinished) {
ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
// The first in the list of RunningTasks is always the foreground task.
RunningTaskInfo foregroundTaskInfo = am.getRunningTasks(1).get(0);
//MORE OF MY CODE GOES HERE -
}
}
}
}