1

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
BigT
  • 21
  • 3
  • Please share your logcat results too.. – akshay bhange Sep 23 '19 at 19:15
  • Many thanks for your quick answer ! – BigT Sep 23 '19 at 19:21
  • 1. replace with try{ mView.invalidate(); } catch(Exception e) { e.printStackTrace();} as the log says mView is null... 2. check Interval value is it too low ( value should be in milliseconds ) 3. mView.invalidate(); is a UI function , why you calling it in Timer just to refresh it ? – Ahmad Sep 23 '19 at 20:55
  • Thanks for your answer, I have modified what you said. Interval = 30 ms. I just want to refresh my View everytime I compute new coordinates for objects. – BigT Sep 24 '19 at 10:10

0 Answers0