私は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;
}