Search code examples
androidtimerbroadcastreceiver

Run time error in timer function in Android Application?


I am trying to get the GPS location for every Half hour using BroadCastReceiver. But I got following error.

Error message

01-09 17:24:44.340: ERROR/AndroidRuntime(2324): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare().

my code

    mTimer = new Timer();
    mTimerTask = new TimerTask() {
    @Override
     public void run() {
      result();//here i cal the Gps function
        }
     };
     mTimer.scheduleAtFixedRate(mTimerTask,1000,50000);

My Method result() is not getting called.


Solution

  • use Handler in run() method.in Handler handle result(); method.