Why is my app slow while I am using a handler and a simple view?

104 Views Asked by At

I am having issues with my application's speed.
My app uses a handler with a timer that computes coordinates of different objects showed on the screen and invalidates a simple view. It works quite well when it is started but it takes 3 or 4 seconds to run at the beginning, and the logcat often prints "skipped frames". I am not very good with the understanding of threads, so I assume the problem comes from here.
I would appreciate if you could have a look at my problem :)

Here is the code I am talking about :

public void resume() {
    keepGoing = true;

    moveFlag = false;

    final Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            mHandler.post(new Runnable() {
                @Override
                public void run() {

                    // ARRET DU CHRONOMETRE
                    if (!keepGoing){
                        cancel();
                    }

                    // MOVING OF THE OBJECTS

                    // REFRESHING THE VIEW
                    mView.invalidate();
                }
            });
        }
    }, 0, Interval);
}

Thank you very much !!

Edit: Here is my logcat results when I start the activity as well :

09-23 21:20:08.893 16382-16382/com.example.myapplication D/ViewRootImpl: #1    mView = com.android.internal.policy.PhoneWindow$DecorView{760d030 I.E...... R.....ID 0,0-0,0}  
09-23 21:20:08.933 16382-16382/com.example.myapplication I/Choreographer: Skipped 75 frames!  The application may be doing too much work on its main thread.
09-23 21:20:08.973 16382-16382/com.example.myapplication W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
09-23 21:20:09.163 16382-16382/com.example.myapplication D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
09-23 21:20:09.213 16382-16382/com.example.myapplication I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@775d973 time:10307099
09-23 21:20:09.463 16382-16382/com.example.myapplication D/ViewRootImpl: #3 mView = null
0

There are 0 best solutions below