Why my tracking service freezes when the phone moves?

Posted by user2878181 on Stack Overflow See other posts from Stack Overflow or by user2878181
Published on 2013-10-24T03:51:41Z Indexed on 2013/10/24 3:53 UTC
Read the original article Hit count: 95

Filed under:

I have developed a service which includes timer task and runs after every 5 minutes for keeping tracking record of the device, every five minutes it adds a record to the database.

My service is working fine when the phone is not moving i.e it gives records after every 5 minutes as it should be. But i have noticed that when the phone is on move it updates the points after 10 or 20 minutes , i.e whenever the user stops in his way whenever he is on the move.

Do service freezes on the move, if yes! how is whatsapp messenger managing it?? Please help! i am writing my onstart method. please help

@Override
public void onStart(Intent intent, int startId) {

    Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
    Log.d(TAG, "onStart");

    mLocationClient.connect();

    final Handler handler_service = new Handler();
    timer_service = new Timer();
    TimerTask thread_service = new TimerTask() {       
        @Override
        public void run() {
            handler_service.post(new Runnable() {
                @Override
                public void run() {       
                    try {
                        some function of tracking
                }
            });
        }
    };
    timer_service.schedule(thread_service, 1000, service_timing);







    //sync thread

    final Handler handler_sync = new Handler();
    timer_sync = new Timer();
    TimerTask thread_sync = new TimerTask() {       
        @Override
        public void run() {
            handler_sync.post(new Runnable() {
                @Override
                public void run() {       
                    try {
                        //connecting to the central server for updation
                        Connect();

                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                    }
                }
            });
        }
    };
    timer_sync.schedule(thread_sync,2000, sync_timing);



}

© Stack Overflow or respective owner

Related posts about android