У меня есть услуга. И есть метод, называемый onServiceUpdate(). Этот метод аналогичен onLocationChanged() в API Карт Google.
Поэтому я хочу запустить CountDownTimer внутри метода onServiceUpdate(), но показывая такую ошибку:
Can't create handler inside thread that has not called Looper.prepare()
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:200)
at android.os.Handler.<init>(Handler.java:114)
at android.os.CountDownTimer$1.<init>(CountDownTimer.java:114)
at android.os.CountDownTimer.<init>(CountDownTimer.java:114)
at skripsi.ubm.studenttracking.Service2$6.<init>(Service2.java:317)
at skripsi.ubm.studenttracking.Service2.onServiceUpdate(Service2.java:317)
Это мой код:
@Override
public void onServiceUpdate(ServiceState state)
{
final float[] distance = new float[2];
Location.distanceBetween(state.getGeoPoint().getLatitude(), state.getGeoPoint().getLongitude(), 6.130607787619352,106.81839518499267, distance);
if (distance[0] > 25.0)
{
CountDownTimer cdt5 = new CountDownTimer(total_onServiceUpdate,1000) {
@Override
public void onTick(long millisUntilFinished) {
total_onServiceUpdate = millisUntilFinished/1000;
}
@Override
public void onFinish() {
sendSMS();
stopSelf();
}
}.start();
}