【发布时间】:2023-03-29 06:53:01
【问题描述】:
我正在尝试像这样在 FirebaseMessagingService 中创建倒计时:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
CountDownTimer countDownTimer;
long timerLeft = 5000;
public void onMessageReceived(RemoteMessage remoteMessage) {
startTimer();
}
public void startTimer() {
countDownTimer = new CountDownTimer(timerLeft, 1000) {
public void onTick(long millisUntilFinished) {
timerLeft = millisUntilFinished;
Log.d("timerleft: ",""+timerLeft);
}
public void onFinish() {
timerLeft=10000;
}
}.start();
}
但是当我收到消息时出现此错误:
java.lang.RuntimeException: Can't create handler inside thread Thread[Firebase-Messaging-Intent-Handle,5,main] that has not called Looper.prepare()
我该如何解决?
【问题讨论】:
标签: android firebase firebase-cloud-messaging runtimeexception android-looper