我在 android 中创建了一个服务,它每 3 秒将 GPS 坐标发送到远程 mysql 数据库。
但是我使用 ScheduledExecutorService 进行了 3 秒循环,但是当我单击开始按钮启动服务时,我得到了 java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
Toast.makeText(this, "Application Started!!!...", Toast.LENGTH_LONG).show();
ScheduledExecutorService scheduleTaskExecutor = Executors.newScheduledThreadPool(5);
// This schedule a runnable task every 2 minutes
scheduleTaskExecutor.scheduleAtFixedRate(new Runnable() {
public void run() {
updateLatLong();
}
}, 0, 3, TimeUnit.SECONDS);
return START_STICKY;
}